-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Go 1.13 compatible error types
Reference: #24 Callers can configure their name and documentation URL to properly customize the error messaging.
- Loading branch information
Showing
6 changed files
with
106 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package awsbase | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// CannotAssumeRoleError occurs when AssumeRole cannot complete. | ||
type CannotAssumeRoleError struct { | ||
Config *Config | ||
Err error | ||
} | ||
|
||
func (e CannotAssumeRoleError) Error() string { | ||
if e.Config == nil { | ||
return fmt.Sprintf("cannot assume role: %s", e.Err) | ||
} | ||
|
||
return fmt.Sprintf(`IAM Role (%s) cannot be assumed. | ||
There are a number of possible causes of this - the most common are: | ||
* The credentials used in order to assume the role are invalid | ||
* The credentials do not have appropriate permission to assume the role | ||
* The role ARN is not valid | ||
Error: %s | ||
`, e.Config.AssumeRoleARN, e.Err) | ||
} | ||
|
||
func (e CannotAssumeRoleError) Unwrap() error { | ||
return e.Err | ||
} | ||
|
||
func (c *Config) NewCannotAssumeRoleError(err error) CannotAssumeRoleError { | ||
return CannotAssumeRoleError{Config: c, Err: err} | ||
} | ||
|
||
// NoValidCredentialSourcesError occurs when all credential lookup methods have been exhausted without results. | ||
type NoValidCredentialSourcesError struct { | ||
Config *Config | ||
Err error | ||
} | ||
|
||
func (e NoValidCredentialSourcesError) Error() string { | ||
if e.Config == nil { | ||
return fmt.Sprintf("no valid credential sources found: %s", e.Err) | ||
} | ||
|
||
return fmt.Sprintf(`no valid credential sources for %s found. | ||
Please see %s | ||
for more information about providing credentials. | ||
Error: %s | ||
`, e.Config.CallerName, e.Config.CallerDocumentationURL, e.Err) | ||
} | ||
|
||
func (e NoValidCredentialSourcesError) Unwrap() error { | ||
return e.Err | ||
} | ||
|
||
func (c *Config) NewNoValidCredentialSourcesError(err error) NoValidCredentialSourcesError { | ||
return NoValidCredentialSourcesError{Config: c, Err: err} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters