errors

package
v0.2103.9 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2022 License: Apache-2.0 Imports: 4 Imported by: 5

Documentation

Overview

Package errors implements errors that can be easily sent across the wire and reconstructed at the other end.

Index

Constants

View Source
const (
	// UnknownModule is the module name used when the module is unknown.
	UnknownModule = "unknown"

	// CodeNoError is the reserved "no error" code.
	CodeNoError = 0
)

Variables

View Source
var (
	As     = errors.As
	Is     = errors.Is
	Unwrap = errors.Unwrap
)

Re-exports so this package can be used as a replacement for errors.

Functions

func Code

func Code(err error) (string, uint32)

Code returns the module and code for the given error.

In case the error is not of the correct type, default values for an unknown error are returned.

In case the error is nil, an empty module name and CodeNoError are returned.

func Context added in v0.2102.0

func Context(err error) string

Context returns the additional context associated with the error.

func FromCode

func FromCode(module string, code uint32, message string) error

FromCode reconstructs a previously registered error from module and code.

In case an error cannot be resolved, this method returns a new error with its message equal to the passed message string.

func New

func New(module string, code uint32, msg string) error

New creates a new error.

Module and code pair must be unique. If they are not, this method will panic.

The error code must not be equal to the reserved "no error" code.

func WithContext added in v0.2102.0

func WithContext(err error, context string) error

WithContext creates a wrapped error that provides additional context.

Types

This section is empty.

Jump to

Keyboard shortcuts

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