diff --git a/notify/sns/sns.go b/notify/sns/sns.go index 104c4a45..38b65236 100644 --- a/notify/sns/sns.go +++ b/notify/sns/sns.go @@ -36,6 +36,12 @@ import ( "github.com/prometheus/alertmanager/types" ) +const ( + // The errors + MessageNotValidUtf8 = "Error - not a valid UTF-8 encoded string" + MessageIsEmpty = "Error - the message should not be empty" +) + // Notifier implements a Notifier for SNS notifications. type Notifier struct { conf *config.SNSConfig @@ -189,7 +195,10 @@ func (n *Notifier) createPublishInput(ctx context.Context, tmpl func(string) str func validateAndTruncateMessage(message string, maxMessageSizeInBytes int) (string, bool, error) { if !utf8.ValidString(message) { - return "", false, fmt.Errorf("non utf8 encoded message string") + return MessageNotValidUtf8, false, fmt.Errorf("non utf8 encoded message string") + } + if len(message) == 0 { + return MessageIsEmpty, false, fmt.Errorf("message is empty") } if len(message) <= maxMessageSizeInBytes { return message, false, nil diff --git a/notify/sns/sns_test.go b/notify/sns/sns_test.go index 7d300ab1..8d8d8b6f 100644 --- a/notify/sns/sns_test.go +++ b/notify/sns/sns_test.go @@ -42,4 +42,8 @@ func TestValidateAndTruncateMessage(t *testing.T) { invalidUtf8String := "\xc3\x28" _, _, err = validateAndTruncateMessage(invalidUtf8String, 100) require.Error(t, err) + + emptyString := "" + _, _, err = validateAndTruncateMessage(emptyString, 100) + require.Error(t, err) }