diff options
author | Ævar Arnfjörð Bjarmason <avarab@gmail.com> | 2020-12-17 11:31:55 +0300 |
---|---|---|
committer | Ævar Arnfjörð Bjarmason <avarab@gmail.com> | 2020-12-17 15:45:35 +0300 |
commit | 8695048d13b1f4f4578cd54596a694687cbda618 (patch) | |
tree | 51cc662f545d09a0cd00c7463b4cf85de0599dc1 | |
parent | b7d42677f27a93b1e6aebb5d571868b9094dc3b2 (diff) |
hooks: assert that we've got s.hookManager instead of dyingavar/assert-hook-manager-not-defined
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
-rw-r--r-- | internal/gitaly/service/operations/update_with_hooks.go | 4 |
1 files changed, 4 insertions, 0 deletions
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} |