Skip to content

Commit

Permalink
Simplify printing and returning error
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerome Touffe-Blin committed Nov 23, 2023
1 parent d1b7643 commit f31e48e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions iam/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit f31e48e

Please sign in to comment.