panichandler

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2023 License: Apache-2.0 Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Crash

func Crash(v interface{})

Crash calls registry's internal Crash function to invoke registered panic handler.

func Go

func Go(f func())

Go calls registry's internal Go function to start f on a new go routine.

func RegisterPanicHandler

func RegisterPanicHandler(ph PanicHandler)

RegisterPanicHandler calls global registry's internal register panic handler function to panic handler registry.

func RegisterPanicHandlers

func RegisterPanicHandlers(in PanicHandlerRegistryIn)

RegisterPanicHandlers register panic handlers to panic handler registry.

Types

type Callstack

type Callstack []uintptr

Callstack is a full stacktrace.

func Capture

func Capture() Callstack

Capture returns a full stacktrace.

func (Callstack) Entries

func (c Callstack) Entries() []Entry

Entries returns all the entries for the stack trace.

func (Callstack) GetEntries

func (c Callstack) GetEntries() map[string]interface{}

GetEntries returns stacktrace of Callstack in map[string]interface{} format.

type Entry

type Entry struct {
	// Location holds the physical location for this entry.
	Location Location
	// Location holds the logical location for this entry.
	Function Function
	// PC is the program counter for this entry.
	PC uintptr
}

Entry holds the human understandable form of a StackTrace entry.

func (Entry) String

func (e Entry) String() string

String returns stacktrace of Entry.

type Function

type Function struct {
	// Package is the go package the stack entry is from.
	Package string
	// Name is the function name the stack entry is from.
	Name string
}

Function holds the logical location of a stack entry.

func (Function) String

func (f Function) String() string

String returns name of Function.

type Location

type Location struct {
	// Directory is the directory the source file is from.
	Directory string
	// File is the filename of the source file.
	File string
	// Line is the line index in the file.
	Line int
}

Location holds the physical location of a stack entry.

func (Location) String

func (l Location) String() string

String returns Location of stack entry.

type PanicHandler

type PanicHandler func(interface{}, Callstack)

PanicHandler is a panic handling function that is called when a panic occurs with full stacktrace.

type PanicHandlerOut

type PanicHandlerOut struct {
	fx.Out
	PanicHandler PanicHandler `group:"panic-handlers"`
}

PanicHandlerOut enables registering panic handlers via Fx.

type PanicHandlerRegistry

type PanicHandlerRegistry struct {
	Handlers []PanicHandler
	// contains filtered or unexported fields
}

PanicHandlerRegistry defines a list of panic handlers.

func (*PanicHandlerRegistry) Crash

func (r *PanicHandlerRegistry) Crash(v interface{})

Crash invokes each of the registered panic handler and then rethrows panic - shutting down the app.

func (*PanicHandlerRegistry) Go

func (r *PanicHandlerRegistry) Go(f func())

Go calls f on a new go-routine, reporting panics to the registered handlers.

func (*PanicHandlerRegistry) RegisterPanicHandler

func (r *PanicHandlerRegistry) RegisterPanicHandler(ph PanicHandler)

RegisterPanicHandler appends panic handler to list of global registry's panic handler.

type PanicHandlerRegistryIn

type PanicHandlerRegistryIn struct {
	fx.In
	Handlers []PanicHandler `group:"panic-handlers"`
}

PanicHandlerRegistryIn holds parameters, list of panic handlers, for RegisterPanicHandlers.

Jump to

Keyboard shortcuts

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