fix(whatsmeow): prevent panic when handling *events.Archive - #177
Open
dev-guidolin wants to merge 1 commit into
Open
fix(whatsmeow): prevent panic when handling *events.Archive#177dev-guidolin wants to merge 1 commit into
dev-guidolin wants to merge 1 commit into
Conversation
postMap["data"] is initialized with the raw event (interface{}), and the
*events.Archive case asserted it directly to map[string]interface{},
which panics on every Archive event. A freshly paired device emits
thousands of Archive events during initial history sync, flooding logs
with recovered panics and dropping every Archive webhook.
Build the data map explicitly, as the other guarded cases already do.
Reviewer's guide (collapsed on small PRs)Reviewer's GuideFixes a panic when handling *events.Archive by no longer type-asserting the raw event to a map and instead constructing the webhook data map explicitly before assigning it back to postMap["data"]. File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- For consistency and to avoid future drift if fields are added to
events.Archive, consider centralizing the struct-to-map conversion (similar to the JSON round-trip used for other guarded cases) into a helper rather than manually constructing the map inline here.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- For consistency and to avoid future drift if fields are added to `events.Archive`, consider centralizing the struct-to-map conversion (similar to the JSON round-trip used for other guarded cases) into a helper rather than manually constructing the map inline here.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
Problem
myEventHandlerinitializespostMap["data"]with the raw event (interface{}). The*events.Archivecase then asserts it directly tomap[string]interface{}:Since
postMap["data"]still holds the*events.Archivestruct at that point, this assertion panics on every single Archive event. whatsmeow recovers the panic, but the Archive webhook is never delivered, and a freshly paired device floods the logs during initial history sync — we measured 2,512 recovered panics in 40 minutes on production (v0.7.2) right after pairing a device with many archived chats:Fix
Build the data map explicitly, the same way the other guarded cases (Connected, LoggedOut, etc.) already do after their JSON round-trip.
Testing
Running in production since 2026-08-18 on a build of v0.7.2 with this patch: zero Archive panics (previously thousands during history sync), Archive webhooks delivered normally.
🤖 Generated with Claude Code
Summary by Sourcery
Bug Fixes: