Improve cli error handler
This commit is contained in:
+14
-1
@@ -1,15 +1,28 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func HandleError(err error) {
|
||||
if err == nil {
|
||||
if err = unwrapGeneric(err); err == nil {
|
||||
return
|
||||
}
|
||||
|
||||
_, _ = fmt.Fprintln(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func unwrapGeneric(err error) error {
|
||||
for {
|
||||
g, ok := err.(interface{ IsGeneric() bool })
|
||||
if ok && g != nil && g.IsGeneric() {
|
||||
err = errors.Unwrap(err)
|
||||
continue
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user