mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-27 02:37:38 +00:00
util/vizerror: add ErrorWithInternal type and func WithInternal
Updates tailscale/corp#23781 Change-Id: I072d0169703aefb0f37b1fa715881f1ccb561f03 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
f6d4d03355
commit
87c0eadf57
@ -48,3 +48,21 @@ func As(err error) (e Error, ok bool) {
|
|||||||
ok = errors.As(err, &e)
|
ok = errors.As(err, &e)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ErrorWithInternal is a tuple of a user-visible error along with
|
||||||
|
// an internal error that should not be shown to users.
|
||||||
|
type ErrorWithInternal struct {
|
||||||
|
UserVisibleErr Error // user-visible half
|
||||||
|
InternalErr error // internal error not to be shown to users
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e ErrorWithInternal) Error() string {
|
||||||
|
return e.UserVisibleErr.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithInternal returns a new ErrorWithInternal combining a user-visible error
|
||||||
|
// string and an internal error to pass around for internal logging but not
|
||||||
|
// to be shown to end users.
|
||||||
|
func WithInternal(visibleError string, internalErr error) error {
|
||||||
|
return ErrorWithInternal{Error{errors.New(visibleError)}, internalErr}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user