handler

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package handler implements handler for objects returned recovery() function.

Index

Constants

View Source
const (
	// Wrapping is best default because we can be in the situation where we
	// have received meaningful sentinel error which we need to wrap, even
	// automatically. If we'd have used %v (no wrapping) we would lose the
	// sentinel error info and we couldn't use annotation for this error.
	// However, we should think about this more later from performance point of
	// view.
	WrapError = ": %w"
)

Variables

This section is empty.

Functions

func LogOutput added in v0.9.5

func LogOutput(lvl int, s string) (err error)

func NilNoop added in v0.8.12

func NilNoop(err error) error

func NoerrCallToDo added in v0.9.5

func NoerrCallToDo(a []any) (yes bool)

NoerrCallToDo returns if we have the _exception case_, aka, func (noerr bool) where these handlers are called even normally only error handlers are called, i.e. those which have error to handle.

func PanicNoop added in v0.8.12

func PanicNoop(any)

func PreProcess added in v0.8.12

func PreProcess(errPtr *error, info *Info, a []any) error

PreProcess is currently used for err2 API like err2.Handle and .Catch.

  • replaces the Process

func Process

func Process(info *Info)

Process executes error handling logic. Panics and whole defer stack is included.

  • err2.API functions call PreProcess and Process is exported for tests.
  • That there is an error or a panic to handle i.e. that's taken care.

func WorkToDo added in v0.8.12

func WorkToDo(r any, err *error) bool

WorkToDo returns if there is something to process. This is offered for optimizations. Starting and executing full error handler stack with the tracers and other stuff is heavy. This function offers us a API to make the decision to abort the processing ASAP.

Types

type CheckHandler added in v0.9.5

type CheckHandler = func(noerr bool)

CheckHandler = func(noerr bool, err error) error

type ErrorFn added in v1.0.0

type ErrorFn = func(err error) error // this is only proper type that work

func Pipeline added in v1.0.0

func Pipeline(f []ErrorFn) ErrorFn

Pipeline is a helper to call several error handlers in a sequence.

defer err2.Handle(&err, err2.Pipeline(err2.Log, MapToHTTPErr))

func ToErrorFns added in v1.0.0

func ToErrorFns(handlerFns []any) (hs []ErrorFn, dis bool)

type Info

type Info struct {
	Any    any    // panic transport object
	Err    *error // error transport pointer (i.e. in/output)
	Format string // format string
	Args   []any  // args for format string printing

	// These are used if handler.Process caller sets them. If they aren't set
	// handler uses package level variables from tracer.
	ErrorTracer io.Writer // If nil tracer package's default is used.
	PanicTracer io.Writer // If nil tracer package's default is used.

	// These are called if handler.Process caller sets it. If they aren't set
	// default implementations are used. NOTE. We have to use both which means
	// that we get nilHandler call if recovery() is called by any other
	// handler then we call still ErrorFn and get the error from Any. It
	// goes for other way around: we get error but nilHandler is only one to
	// set, we use that for the error (which is accessed from the closure).
	ErrorFn // If nil default implementation is used.
	NilFn   // If nil default (pre-defined here) implementation is used.

	PanicFn // If nil panic() is called.

	CheckHandler // this would be for cases where there isn't any error, but

	CallerName string
	// contains filtered or unexported fields
}

Info tells to Process function how to proceed.

type NilFn added in v1.0.0

type NilFn = func(err error) error // these two are the same

type PanicFn added in v1.0.0

type PanicFn = func(p any)

we want these to be type aliases, so they are much nicer to use

Jump to

Keyboard shortcuts

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