Skip to content

fix(whatsmeow): prevent panic when handling *events.Archive - #177

Open
dev-guidolin wants to merge 1 commit into
evolution-foundation:developfrom
dev-guidolin:fix/archive-event-panic
Open

fix(whatsmeow): prevent panic when handling *events.Archive#177
dev-guidolin wants to merge 1 commit into
evolution-foundation:developfrom
dev-guidolin:fix/archive-event-panic

Conversation

@dev-guidolin

@dev-guidolin dev-guidolin commented Aug 18, 2026

Copy link
Copy Markdown

Problem

myEventHandler initializes postMap["data"] with the raw event (interface{}). The *events.Archive case then asserts it directly to map[string]interface{}:

dataMap := postMap["data"].(map[string]interface{})

Since postMap["data"] still holds the *events.Archive struct 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:

[Client ERROR] Event handler panicked while handling a *events.Archive: interface conversion: interface {} is *events.Archive, not map[string]interface {}

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:

  • Prevent Archive event handling from panicking and ensure Archive webhooks are delivered correctly.

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.
@sourcery-ai

sourcery-ai Bot commented Aug 18, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Fixes 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

Change Details Files
Prevent Archive event handler from panicking by replacing the invalid type assertion on postMap["data"] with explicit construction of the data map.
  • Remove direct type assertion of postMap["data"] to map[string]interface{} in the Archive case.
  • Add a new map[string]interface{} literal populated from evt.JID, evt.Timestamp, evt.Action, and evt.FromFullSync.
  • Assign the newly built map back to postMap["data"] so downstream code receives a normalized data payload.
  • Document in a comment that postMap["data"] holds the raw *events.Archive and explain the rationale for building the map explicitly.
pkg/whatsmeow/service/whatsmeow.go

Possibly linked issues

  • #panic: "interface conversion: interface {} is *events.Archive, not map[string]interface {}" can crash the process (v0.7.1): They address the same Archive event panic from mis-asserting *events.Archive; PR fixes serialization to prevent it.
  • #Bug: API /chat/archive - interface conversion panic in *events.Archive (v0.7.2): PR fixes the Archive event handler panic described by building the data map correctly before webhook delivery.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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