From f31e48e05f1e971a56aed050a951afa646050696 Mon Sep 17 00:00:00 2001 From: Jerome Touffe-Blin Date: Fri, 24 Nov 2023 07:25:56 +1100 Subject: [PATCH] Simplify printing and returning error --- iam/iam.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iam/iam.go b/iam/iam.go index cab9073..94cf51a 100644 --- a/iam/iam.go +++ b/iam/iam.go @@ -63,18 +63,18 @@ func getInstanceMetadata(path string) (string, error) { Path: path, }) if err != nil { - return "", errors.New(fmt.Sprintf("EC2 Metadata [%s] response error, got %v", err, path)) + return "", fmt.Errorf("EC2 Metadata [%s] response error, got %v", err, path) } // https://aws.github.io/aws-sdk-go-v2/docs/making-requests/#responses-with-ioreadcloser defer metadataResult.Content.Close() instanceId, err := ioutil.ReadAll(metadataResult.Content) if err != nil { - return "", errors.New(fmt.Sprintf("Expect to read content [%s] from bytes, got %v", err, path)) + return "", fmt.Errorf("Expect to read content [%s] from bytes, got %v", err, path) } if string(instanceId) == "" { - return "", errors.New(fmt.Sprintf("EC2 Metadata didn't returned [%s], got empty string", path)) + return "", fmt.Errorf("EC2 Metadata didn't returned [%s], got empty string", path) } return string(instanceId), nil }