xerror

package
v0.0.0-...-5a98790 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2021 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package xerror helps standardizing the errors through the application.

Credits: https://middlemost.com/failure-is-your-domain/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Invalid

func Invalid(op, message string, previous error) error

Invalid returns a xerror.Error.

Should be used when an input is wrong.

func Message

func Message(err error) string

Message returns the human-readable message of the error, if available. Otherwise returns a generic error message.

func New

func New(op string, previous error) error

New returns a xerror.Error.

Should be used for wrapping an error at the end of a function.

func Op

func Op(err error) string

Op returns the logical operation of the error, if available. Otherwise returns an empty string.

func Timeout

func Timeout(op, message string, previous error) error

Timeout returns a xerror.Error.

Should be used when a timeout occurs.

Types

type Error

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

Error defines our standard application error.

func (Error) Error

func (e Error) Error() string

Error returns the string representation of the error message.

type ErrorCode

type ErrorCode string

ErrorCode is machine-readable error code.

const (
	// InternalCode is an internal error.
	InternalCode ErrorCode = "internal"
	// InvalidCode occurs when a validation
	// failed.
	InvalidCode ErrorCode = "invalid"
	// TimeoutCode occurs when something
	// timed out.
	TimeoutCode ErrorCode = "timeout"
)

func Code

func Code(err error) ErrorCode

Code returns the code of the root error, if available. Otherwise returns InternalCode.

Jump to

Keyboard shortcuts

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