errors

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: MIT Imports: 7 Imported by: 2

README

errors Integration Publication Go Reference

Highly opinionated Go errors package.

Console Output

Console output

Sentry Output

Sentry output

New Relic Output

TODO

Install

go get github.com/neoxelox/errors

Usage

Check and run the example test file errors_test: go test -v --run TestPrint.

See GoDev for further documentation.

Contribute

Feel free to contribute to this project : ) .

License

This project is licensed under the MIT License - read the LICENSE file for details.

Documentation

Overview

Package errors implements functions to deal with error handling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

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

Error represents an error with traceback and additional info.

func New

func New(message string, captureStackTrace ...bool) Error

New creates a new Error with a message (can have a format) and sets to optionally capture the stack trace when raised (default is true).

func (*Error) Cause

func (self *Error) Cause(err error) *Error

Cause wraps an error into the raised Error.

func (Error) Error

func (self Error) Error() string

Error implements the Error interface.

func (*Error) Extra

func (self *Error) Extra(extra map[string]any) *Error

Extra adds extra information to the raised Error.

func (Error) Format

func (self Error) Format(format fmt.State, verb rune)

Format implements the Formatter interface: - %s: Error message - %v: First error report - %+v: All errors reports - default: Error message

func (Error) Has added in v0.2.0

func (self Error) Has(err error) bool

Has checks whether an error is wrapped inside the Error itself.

func (Error) Is

func (self Error) Is(err error) bool

Is compares whether an error is Error's type.

func (Error) MarshalJSON

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

MarshalJSON implements the JSONMarshaler interface.

func (Error) MarshalText

func (self Error) MarshalText() ([]byte, error)

MarshalText implements the TextMarshaler interface.

func (Error) Raise

func (self Error) Raise(args ...any) *Error

Raise creates a new Error instance formatting its message if needed and optionally captures its stack trace.

func (Error) SentryReport added in v0.2.0

func (self Error) SentryReport() *sentry.Event

SentryReport returns a Sentry Event containing all the information about the first error and all errors wrapped within itself (including the types, packages messages, stack traces, extra, tags...).

func (*Error) Skip

func (self *Error) Skip(frames int) *Error

Skip removes n frames of the raised Error.

func (Error) String

func (self Error) String() string

String implements the Stringer interface.

func (Error) StringReport added in v0.2.0

func (self Error) StringReport(all ...bool) string

StringReport returns a string containing all the information about the first error (including the message, stack trace, extra...) or about all errors wrapped within the Error itself (default is all).

func (*Error) Tags added in v0.2.0

func (self *Error) Tags(tags map[string]any) *Error

Tags adds tags to the raised Error to further classify errors in services such as Sentry or New Relic.

func (*Error) With

func (self *Error) With(message string, args ...any) *Error

With adds more context to the raised Error's message.

Jump to

Keyboard shortcuts

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