util/vizerror: add new package for visible errors

Signed-off-by: Will Norris <will@tailscale.com>
This commit is contained in:
Will Norris
2023-01-30 13:22:45 -08:00
committed by Will Norris
parent 27d146d4f8
commit 8e6a1ab175
2 changed files with 54 additions and 0 deletions

24
util/vizerror/vizerror.go Normal file
View File

@@ -0,0 +1,24 @@
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
// Package vizerror provides types and utility funcs for handling visible errors
// that are safe to display to end users.
package vizerror
import (
"errors"
"fmt"
)
// 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))
}
// Errorf returns an error with the specified format and values.
func Errorf(format string, a ...any) error {
return Error(fmt.Errorf(format, a...))
}