Skip to content

Commit

Permalink
Fix blackfriday-slack panics on lists (#980)
Browse files Browse the repository at this point in the history
* fix: blackfriday-slack panics on lists

* Make panic in notifier logged as error
  • Loading branch information
Tetrergeru authored Dec 28, 2023
1 parent ad9cd9b commit 561971e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion notifier/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (notifier *StandardNotifier) reschedule(pkg *NotificationPackage, reason st
func (notifier *StandardNotifier) runSender(sender moira.Sender, ch chan NotificationPackage) {
defer func() {
if err := recover(); err != nil {
notifier.logger.Warning().
notifier.logger.Error().
String(moira.LogFieldNameStackTrace, string(debug.Stack())).
Interface("recovered_err", err).
Msg("Notifier panicked")
Expand Down
3 changes: 1 addition & 2 deletions senders/slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
slackdown "github.com/moira-alert/blackfriday-slack"
"github.com/moira-alert/moira"
"github.com/moira-alert/moira/senders"
blackfriday "github.com/russross/blackfriday/v2"

slack_client "github.com/slack-go/slack"
)
Expand Down Expand Up @@ -134,7 +133,7 @@ func (sender *Sender) buildMessage(events moira.NotificationEvents, trigger moir
func (sender *Sender) buildDescription(trigger moira.TriggerData) string {
desc := trigger.Desc
if trigger.Desc != "" {
desc = string(blackfriday.Run([]byte(desc), blackfriday.WithRenderer(&slackdown.Renderer{})))
desc = string(slackdown.Run([]byte(desc)))
desc += "\n"
}
return desc
Expand Down
19 changes: 19 additions & 0 deletions senders/slack/slack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,23 @@ some other text italic text
So(actual, ShouldResemble, expected)
})
})

Convey("Build desc with lists", t, func() {
trigger := moira.TriggerData{
Desc: `
1. a
`,
}

expected := ` 1. a
`

Convey("Expect buildDescription not to panic", func() {
actual := sender.buildDescription(trigger)

So(actual, ShouldEqual, expected)
})
})
}

0 comments on commit 561971e

Please sign in to comment.