Improve cli error handler

This commit is contained in:
Denis Arh
2020-10-26 08:12:09 +01:00
parent 02c2ffc195
commit 369e9d91f7
+14 -1
View File
@@ -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
}
}