panicsafe

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package panicsafe recovers panics in goroutines that run outside Go's per-request HTTP panic recovery.

net/http only recovers a panic for the goroutine it spawns to handle a given request. A bare `go func() { ... }()` launched from inside a handler, or from a background service (cache warming, search fan-out, fire-and-forget email sending), runs outside that safety net: an unrecovered panic there crashes the entire process, not just the request or task that triggered it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Recover

func Recover(logger *slog.Logger, label string)

Recover recovers a panic in the current goroutine and logs it instead of letting it crash the process. Call it as the first line of any goroutine launched with `go func() { ... }()`:

go func() {
	defer panicsafe.Recover(logger, "cache.warm")
	...
}()

logger may be nil, in which case the panic is still recovered but not logged.

Types

This section is empty.

Jump to

Keyboard shortcuts

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