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>
(cherry picked from commit d3bafa5f3e)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
36 lines
774 B
Go
36 lines
774 B
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"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
|
|
}
|
|
|
|
func (e StatusError) Error() string {
|
|
return fmt.Sprintf("Status: %s, Code: %d", e.Status, e.StatusCode)
|
|
}
|