Skip to content

Conversation

@vduggen
Copy link

@vduggen vduggen commented Jan 14, 2026

📋 Description

Added error logging for WhatsApp Web version fetch operation to improve debugging capabilities. When the request to fetch the latest WhatsApp Web version fails (e.g., due to network issues, blocking, or API changes), the error is now logged with detailed information. This helps identify when Baileys might be using an outdated version due to fetch failures.

The change adds error detection and logging after the version fetch attempt, allowing developers to see:

  • Whether the fetch request succeeded or failed
  • The specific error message if the request was blocked or failed
  • Better visibility into version detection issues

🔗 Related Issue

🧪 Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🔧 Refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🧹 Code cleanup
  • 🔒 Security fix

🧪 Testing

  • Manual testing completed
  • Functionality verified in development environment
  • No breaking changes introduced
  • Tested with different connection types (if applicable)

Test Scenarios:

  • ✅ Verified error logging when network request fails
  • ✅ Verified no errors logged when fetch succeeds
  • ✅ Confirmed existing functionality remains unchanged
  • ✅ Tested with successful version fetch
  • ✅ Tested with blocked/failed requests

📸 Screenshots (if applicable)

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 14, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds error-aware logging after fetching the latest WhatsApp Web (Baileys) version so failures in the version fetch are surfaced without changing existing behavior when the fetch succeeds.

Sequence diagram for Baileys version fetch and error logging

sequenceDiagram
    participant BaileysStartupService
    participant BaileysLibrary as BaileysLibrary
    participant Logger

    BaileysStartupService->>BaileysLibrary: fetchLatestWaWebVersion()
    BaileysLibrary-->>BaileysStartupService: baileysVersion(version, error?)

    BaileysStartupService->>Logger: info("Baileys version: " + version.join('.'))

    alt error present on baileysVersion
        BaileysStartupService->>Logger: error("Fetch latest WaWeb version error: " + error.message)
    else no error
        BaileysStartupService->>Logger: info("Group Ignore: " + localSettings.groupsIgnore)
    end

    BaileysStartupService->>Logger: info("Group Ignore: " + localSettings.groupsIgnore)
Loading

Flow diagram for Baileys WaWeb version error-aware logging

flowchart TD
    A[Start BaileysStartupService startup] --> B[Call fetchLatestWaWebVersion]
    B --> C[Receive baileysVersion with version and optional error]
    C --> D[Log info Baileys version]
    D --> E{baileysVersion.error is not null?}
    E -- Yes --> F[Log error Fetch latest WaWeb version error with error.message]
    E -- No --> G[Skip error logging]
    F --> H[Log info Group Ignore settings]
    G --> H[Log info Group Ignore settings]
    H --> I[Continue startup process]
Loading

File-Level Changes

Change Details Files
Log detailed errors when fetching the latest WhatsApp Web version fails, while keeping existing startup behavior intact.
  • Capture a possible error from the Baileys version fetch result using optional chaining and null fallback.
  • Conditionally log an error message if a fetch error exists, including the underlying error message text.
  • Ensure the new error logging executes after the version is logged and before other startup logs, without altering the existing control flow.
src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

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

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • Consider handling cases where baileysVersion?.error is not an Error instance (e.g., string or unknown) by safely stringifying it or using a type guard, instead of assuming .message exists.
  • If your logger supports structured logging, it may be more useful to pass the full error object (and possibly the requested version/URL) as metadata rather than only logging error.message in the string.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider handling cases where `baileysVersion?.error` is not an `Error` instance (e.g., string or unknown) by safely stringifying it or using a type guard, instead of assuming `.message` exists.
- If your logger supports structured logging, it may be more useful to pass the full `error` object (and possibly the requested version/URL) as metadata rather than only logging `error.message` in the string.

## Individual Comments

### Comment 1
<location> `src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts:649-651` </location>
<code_context>
     const log = `Baileys version: ${version.join('.')}`;
     this.logger.info(log);

+    const error = baileysVersion?.error ?? null;
+    if (error) {
+      this.logger.error(`Fetch latest WaWeb version error: ${error.message}`);
+    }
+
</code_context>

<issue_to_address>
**suggestion:** Log the error object (and/or stack) in addition to the message for better diagnostics.

Currently only `error.message` is logged, which loses useful context (e.g. stack trace or custom fields on non-standard error objects). Instead, log the full error object and/or stack, e.g.:

```ts
const error = baileysVersion?.error;
if (error) {
  this.logger.error('Fetch latest WaWeb version error', { error });
}
```

so failures in fetching the latest WaWeb version are easier to diagnose.
</issue_to_address>

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.

1 participant