diff --git a/service/s3/s3manager/batch.go b/service/s3/s3manager/batch.go index bacdf6e38c1..7f1674f4fa5 100644 --- a/service/s3/s3manager/batch.go +++ b/service/s3/s3manager/batch.go @@ -60,7 +60,15 @@ func newError(err error, bucket, key *string) Error { } func (err *Error) Error() string { - return fmt.Sprintf("failed to upload %q to %q:\n%s", err.Key, err.Bucket, err.OrigErr.Error()) + origErr := "" + if err.OrigErr != nil { + origErr = ":\n" + err.OrigErr.Error() + } + return fmt.Sprintf("failed to upload %q to %q%s", + aws.StringValue(err.Key), + aws.StringValue(err.Bucket), + origErr, + ) } // NewBatchError will return a BatchError that satisfies the awserr.Error interface. diff --git a/service/s3/s3manager/batch_test.go b/service/s3/s3manager/batch_test.go index 8504838b97b..6d8e599feae 100644 --- a/service/s3/s3manager/batch_test.go +++ b/service/s3/s3manager/batch_test.go @@ -321,6 +321,30 @@ func (client *mockS3Client) ListObjects(input *s3.ListObjectsInput) (*s3.ListObj return object, nil } +func TestNilOrigError(t *testing.T) { + err := Error{ + Bucket: aws.String("bucket"), + Key: aws.String("key"), + } + errStr := err.Error() + const expected1 = `failed to upload "key" to "bucket"` + if errStr != expected1 { + t.Errorf("Expected %s, but received %s", expected1, errStr) + } + + err = Error{ + OrigErr: errors.New("foo"), + Bucket: aws.String("bucket"), + Key: aws.String("key"), + } + errStr = err.Error() + const expected2 = "failed to upload \"key\" to \"bucket\":\nfoo" + if errStr != expected2 { + t.Errorf("Expected %s, but received %s", expected2, errStr) + } + +} + func TestBatchDeleteList(t *testing.T) { count := 0