-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherrors.go
45 lines (39 loc) · 986 Bytes
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package liboidcagent
import "fmt"
// OIDCAgentError is an error type used for returning errors
type OIDCAgentError struct {
err string
help string
remote bool
}
func (e OIDCAgentError) Error() string {
rem := ""
if e.remote {
rem = "(remote) "
}
return fmt.Sprintf("oidc-agent %serror: %s", rem, e.err)
}
// Help returns a help message if available. This help message helps the user to
// solve the problem. If a help message is available it SHOULD be displayed to
// the user. One can use ErrorWithHelp to obtain both.
func (e OIDCAgentError) Help() string {
return e.help
}
// ErrorWithHelp returns a string combining the error message and the help
// message (if available).
func (e OIDCAgentError) ErrorWithHelp() string {
help := e.Help()
err := e.Error()
if help != "" {
return fmt.Sprintf("%s\n%s", err, help)
}
return err
}
func oidcAgentErrorWrap(err error) error {
if err == nil {
return nil
}
return &OIDCAgentError{
err: err.Error(),
}
}