The Errors type is no longer used by the CLI itself, and this custom "multi-error" implementation had both limitations (empty list not being `nil`), as well as formatting not being great. All of this making it not something to recommend, and better handled with Go's stdlib. As far as I could find, there's no external consumers of this, but let's deprecate first, and remove in the next release. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
42 lines
977 B
Go
42 lines
977 B
Go
package cli
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// Errors is a list of errors.
|
|
// Useful in a loop if you don't want to return the error right away and you want to display after the loop,
|
|
// all the errors that happened during the loop.
|
|
//
|
|
// Deprecated: use [errors.Join] instead; will be removed in the next release.
|
|
type Errors []error
|
|
|
|
func (errList Errors) Error() string {
|
|
if len(errList) < 1 {
|
|
return ""
|
|
}
|
|
|
|
out := make([]string, len(errList))
|
|
for i := range errList {
|
|
out[i] = errList[i].Error()
|
|
}
|
|
return strings.Join(out, ", ")
|
|
}
|
|
|
|
// StatusError reports an unsuccessful exit by a command.
|
|
type StatusError struct {
|
|
Status string
|
|
StatusCode int
|
|
}
|
|
|
|
// Error formats the error for printing. If a custom Status is provided,
|
|
// it is returned as-is, otherwise it generates a generic error-message
|
|
// based on the StatusCode.
|
|
func (e StatusError) Error() string {
|
|
if e.Status == "" {
|
|
return "exit status " + strconv.Itoa(e.StatusCode)
|
|
}
|
|
return e.Status
|
|
}
|