From 8695048d13b1f4f4578cd54596a694687cbda618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 17 Dec 2020 09:31:55 +0100 Subject: hooks: assert that we've got s.hookManager instead of dying Before this when running with my nascent UserCreateTag in Go code we'd die in auth_test.go with: TestAuthBeforeLimit: auth_test.go:380: Error Trace: auth_test.go:380 Error: Received unexpected error: rpc error: code = Internal desc = panic: runtime error: invalid memory address or nil pointer dereference Test: TestAuthBeforeLimit Now we'll emit the better error message of: rpc error: code = Internal desc = panic: The hookManager must be set up already! Did you migrate non-hook-supporting code from Ruby to Go? To reproduce run: go test -v ./internal/gitaly/server/ -run 'TestAuth' -count=1 See [1] for more background details & further explanation, add a comment pointing to it to aid future debugging. 1. https://gitlab.com/gitlab-org/gitaly/-/merge_requests/2911#note_468836913 --- internal/gitaly/service/operations/update_with_hooks.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/gitaly/service/operations/update_with_hooks.go b/internal/gitaly/service/operations/update_with_hooks.go index ba90634bc..615f8217e 100644 --- a/internal/gitaly/service/operations/update_with_hooks.go +++ b/internal/gitaly/service/operations/update_with_hooks.go @@ -62,6 +62,10 @@ func (s *Server) updateReferenceWithHooks(ctx context.Context, repo *gitalypb.Re changes := fmt.Sprintf("%s %s %s\n", oldrev, newrev, reference) var stdout, stderr bytes.Buffer + if s.hookManager == nil { + // See https://gitlab.com/gitlab-org/gitaly/-/merge_requests/2911#note_468836913 + panic("The hookManager must be set up already! Did you migrate non-hook-supporting code from Ruby to Go?") + } if err := s.hookManager.PreReceiveHook(ctx, repo, env, strings.NewReader(changes), &stdout, &stderr); err != nil { msg := hookErrorFromStdoutAndStderr(stdout.String(), stderr.String()) return preReceiveError{message: msg} -- cgit v1.2.3