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
17
error.go
17
error.go
|
@ -4,9 +4,26 @@ import(
|
||||||
"fmt"
|
"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 {
|
func errStack(err1 error, err2 error) error {
|
||||||
|
if isUnwrapable(err2) {
|
||||||
return fmt.Errorf("%w: %w", err1, err2)
|
return fmt.Errorf("%w: %w", err1, err2)
|
||||||
}
|
}
|
||||||
|
return fmt.Errorf("%w: %v", err1, err2)
|
||||||
|
}
|
||||||
|
|
||||||
func ERR_NOT_TTY() error {
|
func ERR_NOT_TTY() error {
|
||||||
return fmt.Errorf("File is not a tty")
|
return fmt.Errorf("File is not a tty")
|
||||||
|
|
Loading…
Add table
Reference in a new issue