recover

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Component = &component.Component{
	Name: "runner.recover",
	Dependencies: component.Components{
		runner.Component,
	},
	Init: component.StepFunc(func(container container.Container) error {
		return container.Provide(NewRecover)
	}),
	PreExecute: component.StepFunc(func(container container.Container) error {
		return container.Invoke(func(r runner.Runner, middleware *Recover) {
			r.Use(middleware)
		})
	}),
}

Component is a ready-to-use Compogo component that automatically adds panic recovery middleware to the application's runner.

It depends on runner.Component and registers itself during the PreRun phase.

Usage:

compogo.WithComponents(
    runner.Component,
    recover.Component,  // ← protects all tasks from panics
)

Functions

This section is empty.

Types

type Recover

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

Recover is a middleware that catches panics in task execution, logs them with stack traces, and prevents them from crashing the application.

func NewRecover

func NewRecover(logger logger.Logger) *Recover

NewRecover creates a new Recover middleware instance. The provided logger is used to log panic details including stack traces.

func (*Recover) Middleware

func (m *Recover) Middleware(task *runner.Task, next runner.Process) runner.Process

Middleware wraps a task's process function with panic recovery. If the wrapped process panics, it is recovered, logged, and the panic is not propagated further. The task will continue running (the panic only affects the current execution, not the task itself).

Jump to

Keyboard shortcuts

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