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

View File

@ -0,0 +1,30 @@
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
package vizerror
import (
"errors"
"io/fs"
"testing"
)
func TestNew(t *testing.T) {
err := New("abc")
if err.Error() != "abc" {
t.Errorf(`New("abc").Error() = %q, want %q`, err.Error(), "abc")
}
}
func TestErrorf(t *testing.T) {
err := Errorf("%w", fs.ErrNotExist)
if got, want := err.Error(), "file does not exist"; got != want {
t.Errorf("Errorf().Error() = %q, want %q", got, want)
}
// ensure error wrapping still works
if !errors.Is(err, fs.ErrNotExist) {
t.Errorf("error chain does not contain fs.ErrNotExist")
}
}