Skip to content

Conversation

@ljagiello
Copy link
Contributor

@ljagiello ljagiello commented Nov 26, 2025

Summary

  • Update slack-go/slack from v0.17.1 to v0.17.3
  • Add test case to verify the fix

Problem

When Slack API returns errors as strings instead of objects, the library fails with:

json: cannot unmarshal string into Go struct field chatResponseFull.SlackResponse.errors of type map[string]interface{}

This happens because SlackResponseErrors.UnmarshalJSON in v0.17.1 doesn't handle string error values:

var raw map[string]interface{}
if err := json.Unmarshal(data, &raw); err != nil {
    return err   // fails on string errors like ["error_code"]
}

Root Cause

This is a known bug in slack-go/slack, tracked and fixed upstream:

Fix

Simply update the dependency to v0.17.3 which includes the fallback for string errors:

// If we can't unmarshal as object, try as string (fallback case)
var stringError string
if stringErr := json.Unmarshal(data, &stringError); stringErr == nil {
    e.Message = &stringError
    return nil
}

Test plan

  • Added TestSlackErrorStringUnmarshal to verify string errors are handled
  • Added TestSlackErrorObjectUnmarshal to verify object errors still work
  • All tests pass with go test ./...

Fixes error when Slack API returns errors as strings instead of objects:
"json: cannot unmarshal string into Go struct field chatResponseFull.SlackResponse.errors of type map[string]interface{}"

The bug was in SlackResponseErrors.UnmarshalJSON which didn't handle
string error values. This was fixed in slack-go/slack v0.17.2+.

Added test case to verify the fix works.
@korotovsky korotovsky merged commit 0143265 into korotovsky:master Nov 26, 2025
2 checks passed
@ljagiello ljagiello deleted the fix/slack-go-unmarshal-error branch November 26, 2025 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants