Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion internal/hooks/hook_executor_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,14 @@ func (e *HookExecutorDefaultProtocol) Execute(ctx context.Context, opts HookExec

response := strings.TrimSpace(buffout.String())
if err != nil {
// Include stderr outputs in error details if these aren't streamed
details := slackerror.ErrorDetails{}
if opts.Stderr == nil {
details = append(details, slackerror.ErrorDetail{Message: strings.TrimSpace(bufferr.String())})
}
Comment on lines +75 to +79
Copy link
Member Author

@zimeg zimeg Jun 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📣 This guards against duplicating outputs that are streamed for certain hooks, such as local run for ROSI apps or a deploy hook script.

Before changes:

before


After changes:

after

return "", slackerror.New(slackerror.ErrSDKHookInvocationFailed).
WithMessage("Command for '%s' returned an error: %s\n%s", opts.Hook.Name, err, strings.TrimSpace(bufferr.String()))
WithMessage("Error running '%s' command: %s", opts.Hook.Name, err).
WithDetails(details)
}

// Special handling for the baseline protocol for the `start` hook
Expand Down
7 changes: 6 additions & 1 deletion internal/hooks/hook_executor_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ func Test_Hook_Execute_Default_Protocol(t *testing.T) {
},
},
expectedError: slackerror.New(slackerror.ErrSDKHookInvocationFailed).
WithMessage("Command for 'sadpath' returned an error: explosion\nthere was a problem compiling your app"),
WithMessage("Error running 'sadpath' command: explosion").
WithDetails(slackerror.ErrorDetails{
slackerror.ErrorDetail{
Message: "there was a problem compiling your app",
},
}),
expectedResponse: "",
},
"successful deploy command": {
Expand Down
8 changes: 7 additions & 1 deletion internal/hooks/hook_executor_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,14 @@ func (e *HookExecutorMessageBoundaryProtocol) Execute(ctx context.Context, opts

cmd := opts.Exec.Command(cmdEnvVars, &stdout, stderr, opts.Stdin, cmdArgs[0], cmdArgVars...)
if err = cmd.Run(); err != nil {
// Include stderr outputs in error details if these aren't streamed
details := slackerror.ErrorDetails{}
if opts.Stderr == nil {
details = append(details, slackerror.ErrorDetail{Message: strings.TrimSpace(bufferr.String())})
}
return "", slackerror.New(slackerror.ErrSDKHookInvocationFailed).
WithMessage("Error running '%s' command: %s", opts.Hook.Name, err)
WithMessage("Error running '%s' command: %s", opts.Hook.Name, err).
WithDetails(details)
}
return buffout.String(), nil
}
Expand Down
12 changes: 10 additions & 2 deletions internal/hooks/hook_executor_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,21 @@ func Test_Hook_Execute_V2_Protocol(t *testing.T) {
Hook: HookScript{Command: "boom", Name: "sadpath"},
Exec: &MockExec{
mockCommand: &MockCommand{
Err: errors.New("explosion"),
Err: errors.New("explosion"),
MockStderr: []byte("fireworks for the skies above"),
},
},
},
check: func(t *testing.T, response string, err error, mockExec ExecInterface) {
require.Equal(t, slackerror.New(slackerror.ErrSDKHookInvocationFailed).
WithMessage("Error running 'sadpath' command: explosion"), err)
WithMessage("Error running 'sadpath' command: explosion").
WithDetails(slackerror.ErrorDetails{
slackerror.ErrorDetail{
Message: "fireworks for the skies above",
},
}),
err,
)
},
},
"fail to parse payload due to improper boundary strings": {
Expand Down
2 changes: 1 addition & 1 deletion internal/shared/clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func Test_ClientFactory_InitSDKConfigFromJSON_brokenGetHooks(t *testing.T) {
err := clients.InitSDKConfigFromJSON(ctx, []byte(getHooksJSON))
require.Error(t, err)
assert.Equal(t, slackerror.New(slackerror.ErrSDKHookInvocationFailed).Code, slackerror.ToSlackError(err).Code)
assert.Contains(t, slackerror.ToSlackError(err).Message, "Command for 'GetHooks' returned an error")
assert.Contains(t, slackerror.ToSlackError(err).Message, "Error running 'GetHooks' command")
}

func Test_ClientFactory_InitSDKConfigFromJSON_brokenJSONFile(t *testing.T) {
Expand Down
Loading