From e0aaa0bcab617aec5a6742af0bb92b5629a3f672 Mon Sep 17 00:00:00 2001 From: KaiserBh <41852205+KaiserBh@users.noreply.github.com> Date: Mon, 17 Apr 2023 02:44:07 +1000 Subject: [PATCH] fix(notifications): test handle unsupported type (#841) * bugfix: nil pointer dereference if agent variable is nil when the Send method is called, will crash. * refactor: return early. * refactor: idiomatic solution. --------- Co-authored-by: KaiserBh --- internal/notification/service.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/notification/service.go b/internal/notification/service.go index 1d0a472..8433d35 100644 --- a/internal/notification/service.go +++ b/internal/notification/service.go @@ -8,6 +8,7 @@ import ( "github.com/autobrr/autobrr/internal/domain" "github.com/autobrr/autobrr/internal/logger" + "github.com/autobrr/autobrr/pkg/errors" "github.com/rs/zerolog" ) @@ -235,9 +236,12 @@ func (s *service) Test(ctx context.Context, notification domain.Notification) er agent = NewNotifiarrSender(s.log, notification) case domain.NotificationTypeTelegram: agent = NewTelegramSender(s.log, notification) + default: + s.log.Error().Msgf("unsupported notification type: %v", notification.Type) + return errors.New("unsupported notification type") } - g, ctx := errgroup.WithContext(ctx) + g, _ := errgroup.WithContext(ctx) for _, event := range events { e := event