Skip to content

Commit

Permalink
address comments to always wrap errors
Browse files Browse the repository at this point in the history
  • Loading branch information
shijiesheng committed Sep 26, 2024
1 parent 3b9656f commit 605fc74
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions tools/cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func (e printableError) Error() string {
return e.msg
}

func (e printableError) Unwrap() error {
return e.err
}

// JSONHistorySerializer is used to encode history event in JSON
type JSONHistorySerializer struct{}

Expand Down Expand Up @@ -533,15 +537,9 @@ func printError(msg string, err error) {
}
}

// PrintableError returns a printable error
// PrintableError returns a printable error (always wrapping)
func PrintableError(msg string, err error) error {
var printable *printableError
if errors.As(err, &printable) { // already printable error type
printable.msg = msg + ": " + printable.msg
} else {
printable = &printableError{msg: msg, err: err}
}
return printable
return &printableError{msg: msg, err: err}
}

// ExitErrHandler print easy to understand error msg first then error detail in a new line
Expand Down

0 comments on commit 605fc74

Please sign in to comment.