From 1081f3c24c2ab9a468b36ac03b8239135021126f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nils=20m=C3=A5s=C3=A9n?= Date: Sat, 30 May 2020 19:36:20 +0200 Subject: [PATCH] fix(shoutrrr): make shoutrrr init failure a fatal error (#561) also writes out any (unlikely) errors from template.Execute instead of ignoring --- pkg/notifications/notifier.go | 4 +--- pkg/notifications/shoutrrr.go | 7 ++++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/notifications/notifier.go b/pkg/notifications/notifier.go index f22203c..6595b22 100644 --- a/pkg/notifications/notifier.go +++ b/pkg/notifications/notifier.go @@ -47,9 +47,7 @@ func NewNotifier(c *cobra.Command) *Notifier { default: log.Fatalf("Unknown notification type %q", t) } - if tn != nil { - n.types = append(n.types, tn) - } + n.types = append(n.types, tn) } return n diff --git a/pkg/notifications/shoutrrr.go b/pkg/notifications/shoutrrr.go index 58d333b..8cf3d7c 100644 --- a/pkg/notifications/shoutrrr.go +++ b/pkg/notifications/shoutrrr.go @@ -32,8 +32,7 @@ func newShoutrrrNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Noti urls, _ := flags.GetStringArray("notification-url") r, err := shoutrrr.CreateSender(urls...) if err != nil { - fmt.Printf("Failed to initialize Shoutrrr notifications: %s\n", err.Error()) - return nil + log.Fatalf("Failed to initialize Shoutrrr notifications: %s\n", err.Error()) } n := &shoutrrrTypeNotifier{ @@ -50,7 +49,9 @@ func newShoutrrrNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Noti func (e *shoutrrrTypeNotifier) buildMessage(entries []*log.Entry) string { var body bytes.Buffer - e.template.Execute(&body, entries) + if err := e.template.Execute(&body, entries); err != nil { + fmt.Printf("Failed to execute Shoutrrrr template: %s\n", err.Error()) + } return body.String() }