mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-10 09:45:08 +00:00
fixup! util/vizerror: add new package for visible errors
Signed-off-by: Will Norris <will@tailscale.com>
This commit is contained in:
@@ -11,14 +11,31 @@ import (
|
||||
)
|
||||
|
||||
// Error is an error that is safe to display to end users.
|
||||
type Error error
|
||||
|
||||
// New returns an error that formats as the given text.
|
||||
func New(text string) error {
|
||||
return Error(errors.New(text))
|
||||
type Error struct {
|
||||
err error
|
||||
}
|
||||
|
||||
// Errorf returns an error with the specified format and values.
|
||||
func Errorf(format string, a ...any) error {
|
||||
return Error(fmt.Errorf(format, a...))
|
||||
// Error implements the error interface.
|
||||
func (e Error) Error() string {
|
||||
return e.err.Error()
|
||||
}
|
||||
|
||||
// New returns an Error that formats as the given text.
|
||||
func New(text string) Error {
|
||||
return Error{errors.New(text)}
|
||||
}
|
||||
|
||||
// Errorf returns an Error with the specified format and values.
|
||||
func Errorf(format string, a ...any) Error {
|
||||
return Error{fmt.Errorf(format, a...)}
|
||||
}
|
||||
|
||||
// Unwrap returns the underlying error.
|
||||
func (e Error) Unwrap() error {
|
||||
return e.err
|
||||
}
|
||||
|
||||
// Wrap err with a vizerror.Error.
|
||||
func Wrap(err error) Error {
|
||||
return Error{err}
|
||||
}
|
||||
|
Reference in New Issue
Block a user