Skip to content

Commit b644ec6

Browse files
authored
fix(notifier): don't panic on unconfigured notifier (#869)
1 parent 3b60afe commit b644ec6

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

pkg/notifications/notifier.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ func (n *Notifier) String() string {
5555
sb.WriteString(", ")
5656
}
5757
}
58+
59+
if sb.Len() < 2 {
60+
// No notification services are configured, return early as the separator strip is not applicable
61+
return "none"
62+
}
63+
5864
names := sb.String()
5965

6066
// remove the last separator

pkg/notifications/notifier_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@ func TestActions(t *testing.T) {
2323
}
2424

2525
var _ = Describe("notifications", func() {
26+
Describe("the notifier", func() {
27+
When("only empty notifier types are provided", func() {
28+
29+
command := cmd.NewRootCommand()
30+
flags.RegisterNotificationFlags(command)
31+
32+
err := command.ParseFlags([]string{
33+
"--notifications",
34+
"shoutrrr",
35+
})
36+
Expect(err).NotTo(HaveOccurred())
37+
notif := notifications.NewNotifier(command)
38+
39+
Expect(notif.String()).To(Equal("none"))
40+
})
41+
})
2642
Describe("the slack notifier", func() {
2743
builderFn := notifications.NewSlackNotifier
2844

0 commit comments

Comments
 (0)