Skip to content

Bug panic rethrow crashes program#62

Merged
wesm merged 2 commits intowesm:mainfrom
hughdbrown:bug-panic-rethrow-crashes-program
Feb 5, 2026
Merged

Bug panic rethrow crashes program#62
wesm merged 2 commits intowesm:mainfrom
hughdbrown:bug-panic-rethrow-crashes-program

Conversation

@hughdbrown
Copy link
Contributor

Fix panic that crashes program

hughdbrown and others added 2 commits February 4, 2026 21:16
  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 <[email protected]>
@wesm wesm force-pushed the bug-panic-rethrow-crashes-program branch from 914f44c to 1a7b3d7 Compare February 5, 2026 03:17
@wesm wesm merged commit 0a5edd4 into wesm:main Feb 5, 2026
2 checks passed
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.

2 participants