Skip to content

feat: add configurable per-task panic handler - #108

Merged
Yiming1997 merged 1 commit into
mainfrom
feat/configurable-panic-handler
Sep 30, 2026
Merged

Yiming1997 merged 1 commit into
mainfrom
feat/configurable-panic-handler

Conversation

@Yiming1997

Copy link
Copy Markdown
Owner

Add WithPanicHandler so callers can supply a custom callback invoked when a task panics inside a worker, replacing the default logger-based reporting.

Added:

  • PanicHandler type func(task Task, recovered any, stack []byte) and the WithPanicHandler config option in config.go
  • Pool.panicHandler field, initialized from config in NewPool
  • Pool.handlePanic: delegates to the configured handler, or falls back to the previous "worker exits from panic" log line when none is set, and recovers a panicking handler so the worker goroutine survives

Changed:

  • worker.runTask now reports recovered panics via pool.handlePanic instead of logging directly

Tests:

  • Custom handler: receives the exact panicking task, the recovered value and a non-empty stack; the worker keeps serving subsequent tasks
  • Panicking handler is recovered and Wait() still returns

Docs:

  • Document WithPanicHandler in the README options table

Add WithPanicHandler so callers can supply a custom callback invoked
when a task panics inside a worker, replacing the default logger-based
reporting.

Added:
- PanicHandler type func(task Task, recovered any, stack []byte) and the
  WithPanicHandler config option in config.go
- Pool.panicHandler field, initialized from config in NewPool
- Pool.handlePanic: delegates to the configured handler, or falls back to
  the previous "worker exits from panic" log line when none is set, and
  recovers a panicking handler so the worker goroutine survives

Changed:
- worker.runTask now reports recovered panics via pool.handlePanic
  instead of logging directly

Tests:
- Custom handler: receives the exact panicking task, the recovered value
  and a non-empty stack; the worker keeps serving subsequent tasks
- Panicking handler is recovered and Wait() still returns

Docs:
- Document WithPanicHandler in the README options table
@Yiming1997
Yiming1997 merged commit 49d7e8e into main Sep 30, 2026
1 check passed
@Yiming1997
Yiming1997 deleted the feat/configurable-panic-handler branch September 30, 2026 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant