-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
What happened
When posting a message using an invalid set of blocks, we get this go error:
json: cannot unmarshal string into Go struct field chatResponseFull.SlackResponse.errors of type map[string]interface {}
Expected behavior
We'd get a go error describing the issue with post message
Code that caused this to happen was calling post message with this block:
block := []slack.Block{
&slack.SectionBlock{
Type: slack.MBTSection,
Text: &slack.TextBlockObject{
Type: slack.MarkdownType,
Text: ":shrug: neutral response" ,
Emoji: &[]bool{false}[0],
Verbatim: false,
},
},
}
The emoji field should not be there, we had it in our previous code for some reason and when converting to the new version of the library, the Emoji bool became Emoji *bool so we adjusted it. (removing it causes the PostMessage API not fail, but this specific issue is about improper error parsing, adding it here as it's an easy way to trigger the issue)
Cause
The error we are receiving in the slack API (socket mode) is:
{"ok":false,"error":"invalid_blocks","errors":["failed to match all allowed schemas [json-pointer:\/blocks\/3\/text]","invalid additional property: emoji [json-pointer:\/blocks\/3\/text]"],"response_metadata":{"messages":["[ERROR] failed to match all allowed schemas [json-pointer:\/blocks\/3\/text]","[ERROR] invalid additional property: emoji [json-pointer:\/blocks\/3\/text]"]}}
So, we're getting an array of strings back, but a change made recently assumes that we can parse the response as a map[string]interface{}
https://github.com/slack-go/slack/blob/master/misc.go#L68-L71
made in da97682
Will work on code to reproduce / a fix, just wanted to surface it now as it took a fair amount of digging to figure this out, and I wanted to save others some time if they run in to it as I suspect it's an easy to hit issue.
Fix for this, I assume, will be to do a fallback []string parse(or are they always []string?).
Versions
- Go: 1.24.4
- slack-go/slack: 0.17.1