Test if Unwrap method is supported is added.
This commit is contained in:
parent
f10f105886
commit
e7b4f5344e
1 changed files with 18 additions and 1 deletions
19
error.go
19
error.go
|
@ -4,8 +4,25 @@ import(
|
|||
"fmt"
|
||||
)
|
||||
|
||||
type unwraperr interface {
|
||||
Unwrap() error
|
||||
}
|
||||
|
||||
type unwraperrs interface {
|
||||
Unwrap() []error
|
||||
}
|
||||
|
||||
func isUnwrapable(err error) bool {
|
||||
_, ok1 := err.(unwraperr)
|
||||
_, ok2 := err.(unwraperrs)
|
||||
return ok1 || ok2
|
||||
}
|
||||
|
||||
func errStack(err1 error, err2 error) error {
|
||||
return fmt.Errorf("%w: %w", err1, err2)
|
||||
if isUnwrapable(err2) {
|
||||
return fmt.Errorf("%w: %w", err1, err2)
|
||||
}
|
||||
return fmt.Errorf("%w: %v", err1, err2)
|
||||
}
|
||||
|
||||
func ERR_NOT_TTY() error {
|
||||
|
|
Loading…
Add table
Reference in a new issue