Skip to content

Commit 4f110e3

Browse files
authored
Improve error message when credentials can't be found (#10)
1 parent 06d0bd0 commit 4f110e3

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

main.go

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,26 @@ import (
2525
"github.com/goldfiglabs/rpcheckup/pkg/report"
2626
)
2727

28+
type awsAuthError struct {
29+
Err error
30+
}
31+
32+
func (e *awsAuthError) Error() string {
33+
return "Failed to find AWS Credentials"
34+
}
35+
36+
func (e *awsAuthError) Unwrap() error {
37+
return e.Err
38+
}
39+
2840
func loadAwsCredentials(ctx context.Context) ([]string, error) {
2941
cfg, err := config.LoadDefaultConfig(ctx)
3042
if err != nil {
31-
return nil, err
43+
return nil, &awsAuthError{err}
3244
}
3345
creds, err := cfg.Credentials.Retrieve(ctx)
3446
if err != nil {
35-
return nil, err
47+
return nil, &awsAuthError{err}
3648
}
3749
env := []string{
3850
fmt.Sprintf("AWS_ACCESS_KEY_ID=%v", creds.AccessKeyID),
@@ -209,10 +221,24 @@ func main() {
209221
if err != nil {
210222
panic(err)
211223
}
224+
shutdownPostgres := func() {
225+
if !leavePostgresUp {
226+
err = postgresService.ShutDown()
227+
if err != nil {
228+
panic(err)
229+
}
230+
}
231+
}
212232
if !skipIntrospector {
213233
awsCreds, err := loadAwsCredentials(ds.Ctx)
214234
if err != nil {
215-
panic(err)
235+
var authErr *awsAuthError
236+
if errors.As(err, &authErr) {
237+
shutdownPostgres()
238+
log.Fatal("Failed to find AWS Credentials. Please ensure that your enviroment is correctly configued as described here: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html")
239+
} else {
240+
panic(err)
241+
}
216242
}
217243
i, err := introspector.New(ds, postgresService, introspector.Options{
218244
LogDockerOutput: logIntrospector,
@@ -256,10 +282,5 @@ func main() {
256282
panic(err)
257283
}
258284
log.Infof("Reports written to directory %v", outputDir)
259-
if !leavePostgresUp {
260-
err = postgresService.ShutDown()
261-
if err != nil {
262-
panic(err)
263-
}
264-
}
285+
shutdownPostgres()
265286
}

0 commit comments

Comments
 (0)