panicsafe

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package panicsafe turns a panic into a reported, recoverable error instead of a silent process death. The proxy serves many concurrent LLM calls; a panic in any of them (a nil deref, a bad vendor response) would otherwise take the service down with nothing in Sentry to explain it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Guard

func Guard(where string)

Guard recovers a panic in the current goroutine and reports it. Defer it as the first statement inside a spawned goroutine:

go func() {
	defer wg.Done()
	defer panicsafe.Guard("worker: process job")
	...
}()

Deferred functions run last-in-first-out, so Guard (deferred after wg.Done) runs first on a panic — it recovers, then wg.Done still runs, so a panic never leaves a WaitGroup un-Done.

func Report

func Report(where string, r any)

Report captures a recovered panic value as a first-class Sentry exception (with the panic stacktrace, so issues group by origin) and logs a console breadcrumb. It is a no-op when r is nil. Safe when Sentry is disabled: the default hub has no client and the capture/flush become no-ops.

The console line is logged at warn, not error, on purpose: the service's zerolog->Sentry writer captures error-level logs, so logging the panic at error would double-report it. The authoritative Sentry event is the hub.Recover exception below.

Types

This section is empty.

Jump to

Keyboard shortcuts

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