Skip to content

fix(whatsmeow): Archive event panics before reaching the webhook - #195

Open
EcoosUP wants to merge 1 commit into
evolution-foundation:mainfrom
EcoosUP:fix/archive-event-panic
Open

EcoosUP wants to merge 1 commit into
evolution-foundation:mainfrom
EcoosUP:fix/archive-event-panic

Conversation

@EcoosUP

@EcoosUP EcoosUP commented Sep 10, 2026

Copy link
Copy Markdown

The problem

The *events.Archive case asserts postMap["data"] to map[string]interface{}, but at that point it still holds the raw event. The assertion panics every time a chat is archived:

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

postMap["data"] is set to rawEvt before the switch, so this is not a race or an edge case — it fails on every Archive event, in every deployment.

Why nobody noticed

whatsmeow recovers the panic in its event dispatcher and logs it at ERROR level. Nothing crashes, no instance drops. The Archive event simply never reaches the webhook, and the only trace is one line in the log.

We hit it 4 times in 24 hours on a small deployment while investigating something unrelated.

The fix

Every other case in this switch marshals postMap["data"] to JSON and unmarshals it back into a map before asserting. Archive was the only one missing that step.

Six call sites perform this assertion. Five are already guarded (Connected, PairSuccess, TemporaryBan, LoggedOut, and Message, which uses the comma-ok form). This makes Archive the sixth.

A note for reviewers

The marshal/unmarshal block is now repeated five times in this file, and it would read better as a small helper — something like dataMapFrom(postMap). I kept the change minimal and matched the surrounding style instead, since extracting it would touch cases that currently work. Happy to send that as a follow-up if you'd prefer it.

Testing

go build ./... against main, clean.

Summary by Sourcery

Bug Fixes:

  • Prevent Archive events from panicking before webhook delivery by converting their raw event data into the expected map format.

The Archive case asserts postMap["data"] to map[string]interface{}, but at that
point it still holds the raw *events.Archive. The assertion panics on every
archive event:

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

whatsmeow recovers the panic and logs it, so nothing crashes — the event simply
never reaches the webhook, silently.

Every other case in this switch marshals and unmarshals postMap["data"] into a
map before asserting. Archive was the only one missing that step. Six call sites
do the assertion; the other five are already guarded.
@sourcery-ai

sourcery-ai Bot commented Sep 10, 2026

Copy link
Copy Markdown

Reviewer's Guide

The Archive event handler now applies the same JSON normalization used by other event cases before asserting webhook data as a map, eliminating the panic that previously prevented Archive events from reaching the webhook while preserving existing error handling and payload enrichment.

Sequence diagram for normalized Archive webhook delivery

sequenceDiagram
    participant Whatsmeow as Whatsmeow event dispatcher
    participant Handler as myEventHandler
    participant Webhook as Webhook

    Whatsmeow->>Handler: myEventHandler(rawEvt)
    Handler->>Handler: json.Marshal(postMap["data"])
    Handler->>Handler: json.Unmarshal(jsonBytes, &parsed)
    Handler->>Handler: dataMap["JID"] = evt.JID
    Handler->>Handler: dataMap["Timestamp"] = evt.Timestamp
    Handler->>Webhook: Deliver Archive payload
    Webhook-->>Whatsmeow: Archive event received
Loading

File-Level Changes

Change Details Files
Normalize Archive event data before enriching and sending the webhook payload, preventing the raw-event type assertion panic.
  • Marshal the raw Archive event payload to JSON and unmarshal it into a map.
  • Handle nil data with an empty map and log conversion failures before returning.
  • Add Archive JID and timestamp fields to the normalized payload as before.
pkg/whatsmeow/service/whatsmeow.go

Possibly linked issues

  • #unknown: The PR directly fixes the Archive serialization assertion causing the panic described in the issue.
  • #unknown: The PR fixes the exact Archive event type assertion panic reported by the issue, restoring webhook processing.

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 reviewed your changes and they look great!

Sourcery assessment

Needs a human reviewer. This makes Archive events reach the webhook instead of panicking, so an incorrect payload could trigger an external notification or downstream webhook action that cannot be undone by reverting the change. The resulting event is bounded and the implementation can be corrected normally, but already-delivered webhook calls outlive the revert.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

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