diff options
| author | Brad Fitzpatrick <bradfitz@tailscale.com> | 2024-10-09 09:25:07 -0700 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@tailscale.com> | 2024-10-09 09:25:07 -0700 |
| commit | 87c0eadf57f901a6da22cf035212e6de8a2c7dc8 (patch) | |
| tree | 9239678d3e50aba8c8ebc4914dba4e8f1b2daa4b | |
| parent | f6d4d03355ebc5d0fb2269fc2330d36053fbd7fd (diff) | |
| download | tailscale-bradfitz/vizinternal.tar.xz tailscale-bradfitz/vizinternal.zip | |
util/vizerror: add ErrorWithInternal type and func WithInternalbradfitz/vizinternal
Updates tailscale/corp#23781
Change-Id: I072d0169703aefb0f37b1fa715881f1ccb561f03
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
| -rw-r--r-- | util/vizerror/vizerror.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/util/vizerror/vizerror.go b/util/vizerror/vizerror.go index 158786494..8f864f09f 100644 --- a/util/vizerror/vizerror.go +++ b/util/vizerror/vizerror.go @@ -48,3 +48,21 @@ func As(err error) (e Error, ok bool) { ok = errors.As(err, &e) 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} +} |
