Merged
Conversation
The Bug
Both Full() (sync.go:236-241) and Incremental() (incremental.go:46-51) used a defer to catch panics and record the failure in the
database, but then re-threw the panic with panic(r). This crashed the entire program instead of returning a graceful error to the
caller.
The Fix
Three changes per function (identical pattern in both files):
1. Named return values: Changed (*gmail.SyncSummary, error) to (summary *gmail.SyncSummary, err error) so the defer can set the
return values
2. summary := → summary =: Assign to the named return variable instead of shadowing it
3. panic(r) → summary = nil; err = fmt.Errorf("sync panicked: %v", r): Return an error instead of crashing
Changes Made
- internal/sync/sync.go: Named returns, summary =, replace panic(r) with error (3 lines changed)
- internal/sync/incremental.go: Same 3 changes
- internal/sync/sync_test.go: Added panicOnBatchAPI wrapper and TestFullSync_PanicReturnsError test (24 lines)
…emental panic test - Add runtime/debug.Stack() to panic recovery in Full() and Incremental() so stack traces are logged via s.logger.Error for debuggability - Log FailSync errors in panic recovery instead of silently discarding them - Add TestIncrementalSync_PanicReturnsError to cover the Incremental() panic recovery path (parallel to the existing Full() test) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
914f44c to
1a7b3d7
Compare
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.
Fix panic that crashes program