Skip to content

Commit 2f0a77d

Browse files
lambda FunctionError type now outputs all its component fields in a human-readable fashion
1 parent dae956e commit 2f0a77d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

modules/aws/lambda.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ type FunctionError struct {
170170
}
171171

172172
func (err *FunctionError) Error() string {
173-
return fmt.Sprintf("%s error invoking lambda function: %v", err.Message, err.Payload)
173+
return fmt.Sprintf("%q error with status code %d invoking lambda function: %q", err.Message, err.StatusCode, err.Payload)
174174
}
175175

176176
// NewLambdaClient creates a new Lambda client.

modules/aws/lambda_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package aws
2+
3+
import (
4+
"github.com/stretchr/testify/require"
5+
"testing"
6+
)
7+
8+
func TestFunctionError(t *testing.T) {
9+
t.Parallel()
10+
11+
// assert that the error message contains all the components of the error, in a readable form
12+
err := &FunctionError{Message: "message", StatusCode: 123, Payload: []byte("payload")}
13+
require.Contains(t, err.Error(), "message")
14+
require.Contains(t, err.Error(), "123")
15+
require.Contains(t, err.Error(), "payload")
16+
}

0 commit comments

Comments
 (0)