vizerror

package
v1.78.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2024 License: BSD-3-Clause Imports: 2 Imported by: 4

Documentation

Overview

Package vizerror provides types and utility funcs for handling visible errors that are safe to display to end users.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Errorf

func Errorf(publicMsgFormat string, a ...any) error

Errorf returns an Error with the specified publicMsgFormat and values. It always returns a vizerror.Error.

Warning: avoid using an error as one of the format arguments, as this will cause the text of that error to be displayed to the end user (which is probably not what you want).

func New

func New(publicMsg string) error

New returns an error that formats as the given text. It always returns a vizerror.Error.

func Wrap deprecated

func Wrap(publicErr error) error

Wrap wraps publicErr with a vizerror.Error.

Deprecated: this is almost always the wrong thing to do. Are you really sure you know exactly what err.Error() will stringify to and be safe to show to users? WrapWithMessage is probably what you want.

func WrapWithMessage added in v1.76.0

func WrapWithMessage(wrapped error, publicMsg string) error

WrapWithMessage wraps the given error with a message that's safe to display to end users. The text of the wrapped error will not be displayed to end users.

WrapWithMessage should almost always be preferred to Wrap.

Types

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error is an error that is safe to display to end users.

func As

func As(err error) (e Error, ok bool)

As returns the first vizerror.Error in err's chain.

func (Error) Error

func (e Error) Error() string

Error implements the error interface. The returned string is safe to display to end users.

func (Error) Unwrap

func (e Error) Unwrap() error

Unwrap returns the underlying error.

If the Error was constructed using WrapWithMessage, this is the wrapped (internal) error and not the user-visible error message.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL