feat: implement centralized panic recovery mechanism#3039
Open
coolwednesday wants to merge 9 commits intodevelopmentfrom
Open
feat: implement centralized panic recovery mechanism#3039coolwednesday wants to merge 9 commits intodevelopmentfrom
coolwednesday wants to merge 9 commits intodevelopmentfrom
Conversation
Introduces RecoveryHandler, a centralized panic recovery mechanism that replaces scattered ad-hoc defer/recover blocks across the codebase. - Add recovery.go with RecoveryHandler, RecoveryLog, ErrPanic, SafeGo, and SafeGoWithCallback - Replace inline recover() in subscriber.go with NewRecoveryHandler - Replace inline recover() in cron.go with RecoverWithCallback, keeping all metrics instrumentation (total/success/failure counters, histogram) - Replace inline recover() in gofr.go (Migrate) with NewRecoveryHandler - Replace inline recover() in cmd.go with NewRecoveryHandler - Add SafeGo wrappers to shutdown-handler and telemetry goroutines in run.go - Add NewRecoveryHandler to metrics, HTTP, gRPC, and subscription goroutines - Update handler.go to use shared RecoveryLog instead of local panicLog - Update cron_test.go to assert the new component-based log format - Add recovery_test.go with 13 tests covering all RecoveryHandler methods Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Merge latest development changes and fix nolintlint/wsl_v5 linter warnings in recovery.go and cmd.go.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resurrects and improves the work from closed PR #2521, introducing a centralized panic recovery mechanism for GoFr.
recovery.go:RecoveryHandlerstruct withRecover(),RecoverWithCallback(),RecoverWithChannel()methods;SafeGo/SafeGoWithCallbackhelpers; sharedRecoveryLogandErrPanicsentinelsubscriber.go: Replaces ad-hocdefer/recover+ localpanicLog/panicRecoverywithNewRecoveryHandler(...).Recover()cron.go: Replaces inlinerecover()withRecoverWithCallback— all metrics instrumentation (total/success/failure counters, histogram) is preserved with apanickedflag tracked via the callbackgofr.go: UpdatesMigrate()to useNewRecoveryHandler(removes the TODO comment)cmd.go: Wraps command handler execution withNewRecoveryHandler(...).Recover()run.go:startShutdownHandlerandstartTelemetryIfEnableduseSafeGo; metrics, HTTP, gRPC, and subscription-manager goroutines getNewRecoveryHandler(...).Recover()handler.go:panicRecoveryHandleruses sharedRecoveryLoginstead of localpanicLogstructDifferences from PR #2521
cron.go. This PR preserves them using apanickedboolean andRecoverWithCallback.ISSUES.mdexcluded: The original PR added an internal issues file to the repo root. Not included here.go.work.sumnot modified: Only application code is changed.Test plan
go test gofr.dev/pkg/gofrpasses (all 13 new recovery tests + all existing tests)TestCronTab_runScheduled_Panicpasses — verifies cron panic is logged with new component-based formatTestRecoveryHandler_ConcurrentPanics— 10 concurrent goroutines all recover correctlyTestSafeGo/TestSafeGoWithCallback— goroutine-level recovery verifiedRecoverWithCallback