errors

package
v0.0.0-...-7687a33 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Example (WriteHttpJSON)
writeHttpJSON(context.Background(), os.Stdout, fmt.Errorf("dummy error"), true)
Output:

{"error":{"message":"dummy error"}}
Example (WriteHttpJSON_clientAbortedConnectionPipe)
writeHttpJSON(context.Background(), os.Stdout, syscall.EPIPE, true)
Output:

Example (WriteHttpJSON_clientAbortedConnectionReset)
writeHttpJSON(context.Background(), os.Stdout, syscall.ECONNRESET, true)
Output:

Example (WriteHttpPlain)
writeHttpPlain(os.Stdout, fmt.Errorf("dummy error"), true)
Output:

Error: dummy error
Example (WriteHttpPlain_clientAbortedConnectionPipe)
writeHttpPlain(os.Stdout, syscall.EPIPE, true)
Output:

Example (WriteHttpPlain_clientAbortedConnectionReset)
writeHttpPlain(os.Stdout, syscall.ECONNRESET, true)
Output:

Example (WriteHttpPlain_masked)
err := New(0, "dummy error", Meta("a", "b"), Meta(&Error{}, "nope"))
err.stack = nil // will not test the stack as file path & line numbers might change
writeHttpPlain(os.Stdout, err, true)
Output:

Error: dummy error
Example (WriteHttpPlain_unmasked)
err := New(0, "dummy error", Meta("a", "b"), Meta(&Error{}, "nope"))
err.stack = nil // will not test the stack as file path & line numbers might change
writeHttpPlain(os.Stdout, err, false)
Output:

Error: dummy error
--------------------------------------------------------------------------------
a: b
--------------------------------------------------------------------------------

Index

Examples

Constants

View Source
const (
	// internal (unspecified) error
	// these errors yield HTTP status 500 and hide
	// details unless in development environment
	KindInternal kind = iota

	// Data validation error
	KindInvalidData

	// Requested data not found
	KindNotFound

	// Stale data submitted
	// Internally data was already updated or is locked in another session
	KindStaleData

	// Data already exists
	KindDuplicateData

	// Data sensitivity related issue
	KindSensitiveData

	// Access control
	KindUnauthorized

	// Expecting authenticated user
	KindUnauthenticated

	// External system failure
	KindExternal

	// store error
	KindStore

	// object store (file upload/download)
	KindObjStore

	// automation error
	KindAutomation
)

Variables

This section is empty.

Functions

func AddNodeStack

func AddNodeStack(stack []string) mfn

Converts and attaches node.js stack to error

func As

func As(err error, target interface{}) bool

As is alias for errors.As so users can avoid importing both errors packages

func Is

func Is(err, target error) bool

Is is alias for errors.Is so users can avoid importing both errors packages

func IsAny

func IsAny(err error) bool

IsAny returns true if error is of type *Error

func IsAutomation

func IsAutomation(err error) bool

func IsDuplicateData

func IsDuplicateData(err error) bool

func IsExternal

func IsExternal(err error) bool

func IsInternal

func IsInternal(err error) bool

func IsInvalidData

func IsInvalidData(err error) bool

func IsKind

func IsKind(err error, k kind) bool

func IsNotFound

func IsNotFound(err error) bool

func IsObjStore

func IsObjStore(err error) bool

func IsSensitiveData

func IsSensitiveData(err error) bool

func IsStaleData

func IsStaleData(err error) bool

func IsStore

func IsStore(err error) bool

func IsUnauthenticated

func IsUnauthenticated(err error) bool

func IsUnauthorized

func IsUnauthorized(err error) bool

func Meta

func Meta(k, v interface{}) mfn

Adds meta

func MetaTrim

func MetaTrim(kk ...interface{}) mfn

Trim all keys from meta

func ProperlyServeHTTP

func ProperlyServeHTTP(w http.ResponseWriter, r *http.Request, err error, mask bool)

ProperlyServeHTTP Prepares and encodes given error for HTTP transport, same as ServeHTTP but with proper status codes

func ServeHTTP

func ServeHTTP(w http.ResponseWriter, r *http.Request, err error, mask bool)

ServeHTTP Prepares and encodes given error for HTTP transport

mask arg hides extra/debug info

Proper HTTP status codes are generally not used in the API due to compatibility issues This should be addressed in the future versions when/if we restructure the API

func ServeHTTPWithCode

func ServeHTTPWithCode(w http.ResponseWriter, r *http.Request, code int, err error, mask bool)

Serves error via

func StackSkip

func StackSkip(n int) mfn

StackSkip skips n frames in the stack

func StackTrim

func StackTrim(n int) mfn

StackTrim removes n frames from the end of the stack

func StackTrimAtFn

func StackTrimAtFn(fn string) mfn

StackTrimAtFn removes all frames after (inclusive) the (1st) function match

func Unwrap

func Unwrap(err error) error

Unwrap is alias for errors.Unwrap so users can avoid importing both errors packages

This function DOES NOT SUPPRESS errors if they are not wrapped!

func Wrap

func Wrap(w error) mfn

Wrap embeds error

Types

type Error

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

func Automation

func Automation(m string, aa ...interface{}) *Error

func DuplicateData

func DuplicateData(m string, aa ...interface{}) *Error

func External

func External(m string, aa ...interface{}) *Error

func Internal

func Internal(m string, aa ...interface{}) *Error

func InvalidData

func InvalidData(m string, aa ...interface{}) *Error

func New

func New(k kind, m string, fn ...mfn) *Error

New returns *Error

func Newf

func Newf(k kind, m string, a ...interface{}) *Error

New returns *Error with formatted message

func NotFound

func NotFound(m string, aa ...interface{}) *Error

func ObjStore

func ObjStore(m string, aa ...interface{}) *Error

func Plain

func Plain(k kind, m string, a ...interface{}) *Error

Plain returns plain *Error, without call stack and formatted message

func SensitiveData

func SensitiveData(m string, aa ...interface{}) *Error

func StaleData

func StaleData(m string, aa ...interface{}) *Error

func Store

func Store(m string, aa ...interface{}) *Error

func Unauthenticated

func Unauthenticated(m string, aa ...interface{}) *Error

func Unauthorized

func Unauthorized(m string, aa ...interface{}) *Error

func (*Error) Apply

func (e *Error) Apply(ffn ...mfn) *Error

Apply applies modifier functions

func (Error) Error

func (e Error) Error() string

Error message

func (*Error) Is

func (e *Error) Is(target error) bool

Is provided Is() method for equality checking with errors.Is

func (Error) MarshalJSON

func (e Error) MarshalJSON() ([]byte, error)

func (Error) Meta

func (e Error) Meta() meta

Returns error's meta

func (Error) Safe

func (Error) Safe() bool

safe to show details of this error

func (*Error) Stack

func (e *Error) Stack(skip int) *Error

Recollect stack frames

func (Error) Translate

func (e Error) Translate(tr func(string, string, ...string) string) error

func (Error) Unwrap

func (e Error) Unwrap() error

Unwrap wrapped error

func (*Error) Wrap

func (e *Error) Wrap(err error) *Error

Wrap error

type ErrorHandler

type ErrorHandler func(error) error

Jump to

Keyboard shortcuts

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