Skip to content

fix: use correct WebSocket transport and improve error message in PerplexityBot - #1079

Open
octo-patch wants to merge 1 commit into
ai-shifu:mainfrom
octo-patch:fix/issue-925-perplexity-websocket-error
Open

fix: use correct WebSocket transport and improve error message in PerplexityBot#1079
octo-patch wants to merge 1 commit into
ai-shifu:mainfrom
octo-patch:fix/issue-925-perplexity-websocket-error

Conversation

@octo-patch

@octo-patch octo-patch commented Apr 25, 2026

Copy link
Copy Markdown

Fixes #925

Problem

The Perplexity bot was showing [object Event] as the error message when the WebSocket connection failed. There were two bugs:

  1. The WebSocket URL used transport=polling instead of the correct transport=websocket for a WebSocket connection. In socket.io's upgrade flow, the WebSocket endpoint must specify transport=websocket — using transport=polling causes the server to reject or mishandle the upgrade, leading to connection failure.

  2. When the connection failed, reject(event) passed a raw DOM Event object to the rejection handler. When converted to a string via toString(), it produces "[object Event]" — an unhelpful error message shown to users.

Solution

  • Change the WebSocket URL from transport=polling to transport=websocket
  • Replace reject(event) with a localized error message using i18n.global.t("error.failedConnectUrl"), consistent with the pattern already used in MOSSBot.js

Testing

The fix aligns the WebSocket transport with what socket.io expects for a WebSocket upgrade, and ensures error messages are human-readable when the connection fails.

Summary by CodeRabbit

  • Bug Fixes
    • Improved connection reliability through optimized transport protocol
    • Enhanced error handling with localized, user-friendly error messages for better clarity

…plexityBot (fixes ai-shifu#925)

The WebSocket URL incorrectly used `transport=polling` instead of
`transport=websocket`, causing the WebSocket upgrade to fail. When
the connection failed, `reject(event)` was called with a raw DOM
Event object, producing the unhelpful "[object Event]" error message.

- Change WebSocket URL transport from `polling` to `websocket`
- Replace `reject(event)` with a localized error message using
  `i18n.global.t("error.failedConnectUrl")`, consistent with MOSSBot

Co-Authored-By: Octopus <liyuan851277048@icloud.com>
@coderabbitai

coderabbitai Bot commented Apr 25, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Modified error handling and transport protocol in the Perplexity bot by switching from polling to WebSocket transport and replacing raw error rejection with localized error messages using the i18n system.

Changes

Cohort / File(s) Summary
WebSocket Transport & Error Handling
src/bots/PerplexityBot.js
Switched Socket.IO connection from transport=polling to transport=websocket. Enhanced error handling to use localized error messages via i18n.global.t() with fallback to Perplexity base URL instead of raw error events.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A hop, skip, and socket away,
WebSockets now lead the way!
When errors occur (oh, what a fright!),
Localized messages set things right.
No more [object Event], hooray!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and accurately describes the main changes: fixing WebSocket transport configuration and improving error messaging in PerplexityBot.
Linked Issues check ✅ Passed The pull request directly addresses issue #925 by implementing both fixes: correcting the WebSocket transport parameter and replacing raw event errors with localized messages.
Out of Scope Changes check ✅ Passed All changes are scoped to PerplexityBot.js and directly address the linked issue requirements without introducing unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request updates the PerplexityBot to use the websocket transport for its connection and implements localized error messages using i18n. A security concern was raised regarding the exposure of sensitive query parameters, such as session IDs, in the error message's URL; a suggestion was provided to strip these parameters before display to prevent accidental information exposure.

Comment thread src/bots/PerplexityBot.js
reject(event);
reject(
i18n.global.t("error.failedConnectUrl", {
url: event.target?.url ?? "wss://www.perplexity.ai/socket.io/",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security-medium medium

The WebSocket URL contains sensitive query parameters, including the session ID (sid) and a timestamp (t). Displaying the full URL in the error message could lead to accidental exposure of these tokens if a user shares a screenshot of the error. It is safer to strip the query parameters and only display the base URL in the UI.

Suggested change
url: event.target?.url ?? "wss://www.perplexity.ai/socket.io/",
url: event.target?.url?.split("?")[0] ?? "wss://www.perplexity.ai/socket.io/",

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/bots/PerplexityBot.js (1)

310-318: Localized error rejection looks good; minor convention nit.

The handler now rejects with a human-readable, translated message and includes a sensible fallback URL when event.target?.url is unavailable, matching the MOSSBot pattern (src/bots/MOSSBot.js:126-134). This resolves the "[object Event]" symptom from issue #925.

Optional nit: like MOSSBot, this rejects with a raw string rather than an Error instance, which can lose stack-trace context for any upstream catch that expects error.message. If callers don't depend on that, feel free to ignore — keeping consistency with MOSSBot has its own value. If you'd like to harden it without changing the displayed text:

♻️ Optional: wrap in Error for consistent error shape
         wsp.onError.addListener((event) => {
           wsp.removeAllListeners();
           wsp.close();
           reject(
-            i18n.global.t("error.failedConnectUrl", {
-              url: event.target?.url ?? "wss://www.perplexity.ai/socket.io/",
-            }),
+            new Error(
+              i18n.global.t("error.failedConnectUrl", {
+                url: event.target?.url ?? "wss://www.perplexity.ai/socket.io/",
+              }),
+            ),
           );
         });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/bots/PerplexityBot.js` around lines 310 - 318, The onError listener in
PerplexityBot.js currently calls reject(...) with a localized string; change it
to reject(new Error(...)) so the rejection is an Error instance (preserving
stack and shape) while still using the same
i18n.global.t("error.failedConnectUrl", { url: ... }) message and the same
fallback URL; update the wsp.onError.addListener callback to construct an Error
with that translated message before calling reject so behavior matches MOSSBot's
convention and retains the human-readable localized text.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/bots/PerplexityBot.js`:
- Around line 310-318: The onError listener in PerplexityBot.js currently calls
reject(...) with a localized string; change it to reject(new Error(...)) so the
rejection is an Error instance (preserving stack and shape) while still using
the same i18n.global.t("error.failedConnectUrl", { url: ... }) message and the
same fallback URL; update the wsp.onError.addListener callback to construct an
Error with that translated message before calling reject so behavior matches
MOSSBot's convention and retains the human-readable localized text.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 31ac597f-b81e-4f39-88c4-72250a8aadef

📥 Commits

Reviewing files that changed from the base of the PR and between 6d089c2 and 216a74e.

📒 Files selected for processing (1)
  • src/bots/PerplexityBot.js

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.

[BUG] Perplexity [object Event] ERROR

1 participant