-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
36 lines (31 loc) · 972 Bytes
/
errors.go
File metadata and controls
36 lines (31 loc) · 972 Bytes
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
package sysproxy
import "errors"
// nonCriticalError wraps errors from operations that do not invalidate the
// overall request. For example, /etc/environment on Linux requires root; if
// the rest of the configuration (GNOME/KDE/process env) succeeded, the caller
// should be able to distinguish that warning from a hard failure.
type nonCriticalError struct {
err error
}
func (e *nonCriticalError) Error() string {
if e == nil || e.err == nil {
return "sysproxy: non-critical error"
}
return e.err.Error()
}
func (e *nonCriticalError) Unwrap() error {
if e == nil {
return nil
}
return e.err
}
// IsNonCritical reports whether err is a non-fatal warning emitted by sysproxy
// (for example, failure to write /etc/environment without root privileges).
// When true, the rest of the operation should be considered successful.
func IsNonCritical(err error) bool {
if err == nil {
return false
}
var nc *nonCriticalError
return errors.As(err, &nc)
}