From 9c94d30209c7451be7ce0c1ad3737cf4b31617d0 Mon Sep 17 00:00:00 2001 From: Nate Maninger Date: Thu, 7 Dec 2023 16:53:31 -0800 Subject: [PATCH] webhooks: panic if webhook is not properly unregistered --- webhooks/webhooks.go | 6 +++++- webhooks/webhooks_test.go | 1 - 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/webhooks/webhooks.go b/webhooks/webhooks.go index 902f636..1c93c76 100644 --- a/webhooks/webhooks.go +++ b/webhooks/webhooks.go @@ -85,7 +85,11 @@ func (m *Manager) findMatchingHooks(s string) (hooks []WebHook) { var match func(scopeParts []string, parent *scope) match = func(scopeParts []string, parent *scope) { for id := range parent.hooks { - hooks = append(hooks, m.hooks[id]) + hook, ok := m.hooks[id] + if !ok { + panic("hook not found") // developer error + } + hooks = append(hooks, hook) } if len(scopeParts) == 0 { return diff --git a/webhooks/webhooks_test.go b/webhooks/webhooks_test.go index 705d870..f30ca37 100644 --- a/webhooks/webhooks_test.go +++ b/webhooks/webhooks_test.go @@ -146,5 +146,4 @@ func TestWebHooks(t *testing.T) { t.Fatal("expected no event") } } - }