Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not log full Slack event details in case of unmarshalling error #583
##### ISSUE TYPE - Bug fix Pull Request ##### SUMMARY - Do not log full Slack event details in case of unmarshalling error This is an issue of the upstream library. While I prepared a workaround, I also prepared a simple change in `slack-go/slack` repo: slack-go/slack#1067 **NOTE:** This pull request depends on #582. Please merge #582 first, and I will rebase this one. Actual changes on this PR: 7813821 Fixes #579 ##### TESTING See the original issue for testing instruction: #579 You can use `pkosiec/botkube:slack-unmarshall-err` Docker image for testing the workaround. Once you run my image and try to reproduce the issue, you'll see in the logs: ``` ERRO[2022-05-19T16:00:57Z] Slack unmarshalling error: RTM Error: Received unmapped event "user_huddle_changed" ERRO[2022-05-19T16:00:57Z] Slack unmarshalling error: RTM Error: Received unmapped event "sh_room_join" ERRO[2022-05-19T16:01:00Z] Slack unmarshalling error: RTM Error: Received unmapped event "sh_room_leave" ```
- Loading branch information
Showing
3 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package bot | ||
|
||
func (b *SlackBot) StripUnmarshallingErrEventDetails(errMessage string) string { | ||
return b.stripUnmarshallingErrEventDetails(errMessage) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package bot_test | ||
|
||
import ( | ||
"fmt" | ||
"github.com/infracloudio/botkube/pkg/bot" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestSlackBot_StripUnmarshallingErrEventDetails(t *testing.T) { | ||
//given | ||
sampleEvent := `{"type":"user_huddle_changed","user":{"id":"id","team_id":"team_id"}, "event_ts":"1652949120.004700"}` | ||
|
||
testCases := []struct { | ||
Name string | ||
Input string | ||
Expected string | ||
}{ | ||
{ | ||
Name: "Unmapped event", | ||
Input: fmt.Sprintf(`RTM Error: Received unmapped event "user_huddle_changed": %s`, sampleEvent), | ||
Expected: `RTM Error: Received unmapped event "user_huddle_changed"`, | ||
}, | ||
{ | ||
Name: "Unmarshalling error message", | ||
Input: fmt.Sprintf(`RTM Error: Could not unmarshall event "user_huddle_changed": %s`, sampleEvent), | ||
Expected: `RTM Error: Could not unmarshall event "user_huddle_changed"`, | ||
}, | ||
{ | ||
Name: "JSON unmarshal error", | ||
Input: "cannot unmarshal bool into Go value of type string", | ||
Expected: "cannot unmarshal bool into Go value of type string", | ||
}, | ||
{ | ||
Name: "JSON unmarshal error with colons", | ||
// this is a real error when doing json.Unmarshal([]byte(`":::"`), &time) | ||
Input: `parsing time "":::"" as ""2006-01-02T15:04:05Z07:00"": cannot parse ":::"" as "2006"`, | ||
Expected: `parsing time "":::"" as ""2006-01-02T15:04:05Z07:00"": cannot parse ":::"" as "2006"`, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
t.Run(testCase.Name, func(t *testing.T) { | ||
slackBot := &bot.SlackBot{} | ||
|
||
// when | ||
actual := slackBot.StripUnmarshallingErrEventDetails(testCase.Input) | ||
|
||
// then | ||
assert.Equal(t, testCase.Expected, actual) | ||
}) | ||
} | ||
} |