From 2f0a77df0d8b9d73c4a760945207257d8f52fa8c Mon Sep 17 00:00:00 2001 From: "R. Aidan Campbell" Date: Sat, 19 Mar 2022 16:50:35 -0700 Subject: [PATCH] lambda FunctionError type now outputs all its component fields in a human-readable fashion --- modules/aws/lambda.go | 2 +- modules/aws/lambda_test.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 modules/aws/lambda_test.go diff --git a/modules/aws/lambda.go b/modules/aws/lambda.go index 634d7290a..5630613ca 100644 --- a/modules/aws/lambda.go +++ b/modules/aws/lambda.go @@ -170,7 +170,7 @@ type FunctionError struct { } func (err *FunctionError) Error() string { - return fmt.Sprintf("%s error invoking lambda function: %v", err.Message, err.Payload) + return fmt.Sprintf("%q error with status code %d invoking lambda function: %q", err.Message, err.StatusCode, err.Payload) } // NewLambdaClient creates a new Lambda client. diff --git a/modules/aws/lambda_test.go b/modules/aws/lambda_test.go new file mode 100644 index 000000000..053f2bda4 --- /dev/null +++ b/modules/aws/lambda_test.go @@ -0,0 +1,16 @@ +package aws + +import ( + "github.com/stretchr/testify/require" + "testing" +) + +func TestFunctionError(t *testing.T) { + t.Parallel() + + // assert that the error message contains all the components of the error, in a readable form + err := &FunctionError{Message: "message", StatusCode: 123, Payload: []byte("payload")} + require.Contains(t, err.Error(), "message") + require.Contains(t, err.Error(), "123") + require.Contains(t, err.Error(), "payload") +}