Skip to content

Add panic recovery for task handlers#12

Merged
anish749 merged 5 commits intomainfrom
feature/panic-recovery
Jan 20, 2026
Merged

Add panic recovery for task handlers#12
anish749 merged 5 commits intomainfrom
feature/panic-recovery

Conversation

@anish749
Copy link
Owner

Summary

  • Adds panic recovery to prevent worker goroutines from crashing when handlers panic
  • Panics are converted to errors and handled through the normal retry flow
  • Includes comprehensive unit tests for the panic recovery module

Test plan

  • All existing tests pass
  • New panic recovery tests pass

🤖 Generated with Claude Code

anish749 and others added 5 commits January 20, 2026 08:43
Wrap task handler execution with panic recovery to prevent worker
goroutines from crashing when handlers panic. Panics are now captured
as PanicError and flow through the normal error handling and retry
logic.

- Add PanicError type with panic value and stack trace
- Add SafeExecute generic function for panic-safe execution
- Add SafeHandler and SafeResourceKeyHandler wrappers
- Integrate panic recovery into runLoop for all handler types
- Add comprehensive unit tests for panic recovery

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove PanicError struct and helper functions (IsPanicError, AsPanicError)
- Log stack trace immediately via slog.ErrorContext instead of storing it
- Return simple error with panic value
- Update SafeExecute to take context parameter for logging
- Simplify tests to match new API

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace SafeHandler and SafeResourceKeyHandler wrappers with a single
generic SafeExecute[P, R] function that works with any handler signature.

Usage: result, err := SafeExecute(ctx, handler, param)

This reduces code and makes the panic recovery more flexible - it works
with any function matching func(context.Context, P) (R, error).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Consolidate individual test functions into table-driven tests
- Group related test cases: basic execution, panic recovery, handler types
- Fix struct field alignment for linter

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@anish749 anish749 merged commit 4074229 into main Jan 20, 2026
4 checks passed
@anish749 anish749 deleted the feature/panic-recovery branch January 20, 2026 11:21
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