From 70bd4e2c8bca5b50fc976c97d44257282beb4aa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nils=20m=C3=A5s=C3=A9n?= Date: Fri, 29 May 2020 11:02:13 +0200 Subject: [PATCH] fix(shoutrrr): display errors on init failure (#558) --- pkg/notifications/notifier.go | 4 +++- pkg/notifications/shoutrrr.go | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pkg/notifications/notifier.go b/pkg/notifications/notifier.go index 6595b22..f22203c 100644 --- a/pkg/notifications/notifier.go +++ b/pkg/notifications/notifier.go @@ -47,7 +47,9 @@ func NewNotifier(c *cobra.Command) *Notifier { default: log.Fatalf("Unknown notification type %q", t) } - n.types = append(n.types, tn) + if tn != nil { + n.types = append(n.types, tn) + } } return n diff --git a/pkg/notifications/shoutrrr.go b/pkg/notifications/shoutrrr.go index 04fbf8b..58d333b 100644 --- a/pkg/notifications/shoutrrr.go +++ b/pkg/notifications/shoutrrr.go @@ -30,7 +30,11 @@ func newShoutrrrNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Noti flags := c.PersistentFlags() urls, _ := flags.GetStringArray("notification-url") - r, _ := shoutrrr.CreateSender(urls...) + r, err := shoutrrr.CreateSender(urls...) + if err != nil { + fmt.Printf("Failed to initialize Shoutrrr notifications: %s\n", err.Error()) + return nil + } n := &shoutrrrTypeNotifier{ Urls: urls, @@ -52,8 +56,10 @@ func (e *shoutrrrTypeNotifier) buildMessage(entries []*log.Entry) string { } func (e *shoutrrrTypeNotifier) sendEntries(entries []*log.Entry) { - // Do the sending in a separate goroutine so we don't block the main process. + msg := e.buildMessage(entries) + + // Do the sending in a separate goroutine so we don't block the main process. go func() { errs := e.Router.Send(msg, nil)