panichandler

package
v2.18.1-rc.1 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

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 FxOnDone added in v2.17.0

func FxOnDone(doneChan <-chan struct{}, onDone func(context.Context), lifecycle fx.Lifecycle)

FxOnDone is a helper that wraps NewCancellableWaitGroup + GoOnDone in an fx lifecycle. It registers a callback to be called when the given channel is closed.

The callback will be called only within period between Start and Stop (if channel is closed before Start, callback will be delayed to until Start).

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 CancellableWaitGroup added in v2.17.0

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

CancellableWaitGroup combines a WaitGroup with a cancellable context.

The zero value of CancellableWaitGroup is not usable.

func NewCancellableWaitGroup added in v2.17.0

func NewCancellableWaitGroup() *CancellableWaitGroup

NewCancellableWaitGroup creates a new CancellableWaitGroup.

func (*CancellableWaitGroup) CancelAndWait added in v2.17.0

func (cwg *CancellableWaitGroup) CancelAndWait()

CancelAndWait cancels all the running goroutines and waits for them to finish.

func (*CancellableWaitGroup) Ctx added in v2.17.0

Ctx returns the context that will be canceled on Cancel.

func (*CancellableWaitGroup) Go added in v2.17.0

func (cwg *CancellableWaitGroup) Go(f func(context.Context))

Go spawns a new goroutine in the WaitGroup using panichandler.Go.

func (*CancellableWaitGroup) GoOnDone added in v2.17.0

func (cwg *CancellableWaitGroup) GoOnDone(doneChan <-chan struct{}, onDone func(context.Context))

GoOnDone registers a callback to be called when the given channel is closed. Waiting can be canceled using CancelAndWait.

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.

type WaitGroup added in v2.17.0

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

WaitGroup allows spawning and waiting for goroutines.

(This is similar to https://pkg.go.dev/github.com/sourcegraph/conc#WaitGroup, but using the panichandler.Go to spawn goroutines).

The zero value of WaitGroup is usable, just like sync.WaitGroup.

func (*WaitGroup) Go added in v2.17.0

func (wg *WaitGroup) Go(f func())

Go spawns a new goroutine in the WaitGroup using panichandler.Go.

func (*WaitGroup) Wait added in v2.17.0

func (wg *WaitGroup) Wait()

Wait waits for all previously spawned goroutines.

Jump to

Keyboard shortcuts

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