-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patherror.go
38 lines (32 loc) · 784 Bytes
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package patch2pr
import (
"errors"
"fmt"
)
func unsupported(msg string, args ...interface{}) error {
return unsupportedErr{reason: fmt.Sprintf(msg, args...)}
}
type unsupportedErr struct {
reason string
}
func (err unsupportedErr) Error() string {
return fmt.Sprintf("unsupported: %s", err.reason)
}
func (err unsupportedErr) Unsupported() bool {
return true
}
// IsUnsupported returns true if err is the result of trying an unsupported
// operation. It is equivalent to finding the first error in err's chain that
// implements
//
// type unsupported interface {
// Unsupported() bool
// }
//
// and then calling the Unsupported() method.
func IsUnsupported(err error) bool {
var u interface {
Unsupported() bool
}
return errors.As(err, &u) && u.Unsupported()
}