eerror

package
v1.29.5 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2023 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package eerror stands for Encore Error and is used to provide a little more information about the underlying error's metadata.

It also provides helper methods for working with zerolog's context

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BottomStackTraceFrom added in v1.11.0

func BottomStackTraceFrom(err error) (rtn errors.StackTrace)

BottomStackTraceFrom returns the deepest stack trace from the given error

func LogWithMeta

func LogWithMeta(evt *zerolog.Event, err error) *zerolog.Event

LogWithMeta merges in the metadata from the errors into the log context

func MetaFrom

func MetaFrom(err error) map[string]any

MetaFrom will return the merged metadata from any eerror.Error objects in the errors given. It will unwrap errors as it descends

func New

func New(module string, msg string, meta map[string]any) error

New creates a new error with the given error

func WithMeta

func WithMeta(err error, meta map[string]any) error

func Wrap

func Wrap(cause error, module string, msg string, meta map[string]any) error

Wrap wraps the cause error with the given message and meta. If cause is nil, wrap returns nil

func ZeroLogConsoleExtraFormatter added in v1.11.0

func ZeroLogConsoleExtraFormatter(event map[string]any, buf *bytes.Buffer) error

ZeroLogConsoleExtraFormatter extracts the extra fields from the error and formats them for console output

This field can be passed to a zerolog.ConsoleWriter as it's ExtraFieldFormatter

func ZeroLogStackMarshaller added in v1.11.0

func ZeroLogStackMarshaller(err error) interface{}

ZeroLogStackMarshaller will encode the following in the Zerolog error stack field: - the deepest error stack trace - the error meta data collected from all errors

This can then be extracted by ZeroLogConsoleExtraFormatter

Types

type Error

type Error struct {
	Module  string         `json:"module"`  // The module the error was raised in (normally the package name, but could be a larger "module" name)
	Message string         `json:"message"` // The message of the error, it should be human-readable and should be low entropy (i.e. so multiple errors of the same can be grouped)
	Meta    map[string]any `json:"meta"`    // Metadata about the error, this can be high entropy as it isn't used to group errors
	Stack   []*StackFrame  `json:"stack"`   // The stack trace of the error
	// contains filtered or unexported fields
}

func (*Error) Cause

func (e *Error) Cause() error

Cause implements Causer for some libraries and returns the underlying cause

func (*Error) Error

func (e *Error) Error() string

Error returns a simple string of the error

func (*Error) MarshalZerologObject added in v1.11.0

func (e *Error) MarshalZerologObject(evt *zerolog.Event)

MarshalZerologObject provides a strongly-typed and encoding-agnostic interface to be implemented by types used with Event/Context's Object methods.

func (*Error) StackTrace

func (e *Error) StackTrace() errors.StackTrace

StackTrace implements the StackTraceProvider interface for some libraries including ZeroLog, xerrors and Sentry

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap implements the Go 2 unwrap interface used by xerrors and errors

type StackFrame

type StackFrame struct {
	// PC is the program counter for the frame (needed for things like sentry reporting)
	PC uintptr `json:"pc"`

	// Human-readable fields
	Function string `json:"function"`
	File     string `json:"file"`
	Line     int    `json:"line"`
}

Jump to

Keyboard shortcuts

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