Skip to content

fix: pass error message string instead of Error object to toast dispatcher #40244

Open
Naetiksoni08 wants to merge 2 commits into
RocketChat:developfrom
Naetiksoni08:fix/toast-error-message-object
Open

fix: pass error message string instead of Error object to toast dispatcher #40244
Naetiksoni08 wants to merge 2 commits into
RocketChat:developfrom
Naetiksoni08:fix/toast-error-message-object

Conversation

@Naetiksoni08
Copy link
Copy Markdown
Contributor

@Naetiksoni08 Naetiksoni08 commented Apr 21, 2026

Proposed changes (including videos or screenshots)

In multiple composer files and useClipboardWithToast.ts, the dispatchToastMessage was being called with an Error object directly as the message field:

// Before (broken)                                                                                                                                              
dispatchToastMessage({ type: 'error', message: error });

Since message expects a string, passing an Error object causes the toast to display [object Object] instead of the actual error message — making error toasts completely uninformative to the user.

Fix

 // After (fixed)                                                                                                                                                
  dispatchToastMessage({ type: 'error', message: error instanceof Error ? error.message : String(error) });

This correctly extracts the error message string in all cases.

Files changed

  • apps/meteor/client/hooks/useClipboardWithToast.ts
  • apps/meteor/client/views/room/composer/ComposerReadOnly.tsx
  • apps/meteor/client/views/room/composer/ComposerMessage.tsx
  • apps/meteor/client/views/room/composer/ComposerJoinWithPassword.tsx
  • apps/meteor/client/views/room/composer/ComposerOmnichannel/ComposerOmnichannelInquiry.tsx
  • apps/meteor/client/views/room/composer/ComposerOmnichannel/ComposerOmnichannelJoin.tsx
  • apps/meteor/client/views/room/composer/ComposerOmnichannel/hooks/useResumeChatOnHoldMutation.ts

Steps to test or reproduce

  1. In any room, trigger an error in the composer (e.g. try joining a channel that fails)
  2. Before fix: toast shows [object Object]
  3. After fix: toast shows the actual error message

Further comments

Same pattern fixed across 7 files in the composer area.

Summary by CodeRabbit

  • Bug Fixes
    • Improved error notifications across the composer UI: toast messages now consistently show readable, human-friendly text instead of raw error objects. This yields clearer feedback for failures when sending messages, joining rooms, taking inquiries, resuming chats on hold, and in read-only composer views.

@Naetiksoni08 Naetiksoni08 requested a review from a team as a code owner April 21, 2026 11:48
@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot Bot commented Apr 21, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 21, 2026

⚠️ No Changeset found

Latest commit: 874911e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 21, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 81e9a86b-f5c0-44d4-b1eb-63603130adae

📥 Commits

Reviewing files that changed from the base of the PR and between b385de2 and 874911e.

📒 Files selected for processing (1)
  • apps/meteor/client/views/room/composer/ComposerJoinWithPassword.tsx
✅ Files skipped from review due to trivial changes (1)
  • apps/meteor/client/views/room/composer/ComposerJoinWithPassword.tsx

Walkthrough

Normalized error-to-string conversion for toast notifications across clipboard and composer-related components/hooks by using error instanceof Error ? error.message : String(error).

Changes

Cohort / File(s) Summary
Clipboard Error Handling
apps/meteor/client/hooks/useClipboardWithToast.ts
Changed onCopyError to derive the toast message via error instanceof Error ? error.message : String(error) to safely handle non-Error values.
Composer Components
apps/meteor/client/views/room/composer/ComposerJoinWithPassword.tsx, apps/meteor/client/views/room/composer/ComposerMessage.tsx, apps/meteor/client/views/room/composer/ComposerReadOnly.tsx
Standardized toast error payloads to pass a string message (use .message for Error, else String(error)) instead of raw caught values.
Omnichannel Composer Components
apps/meteor/client/views/room/composer/ComposerOmnichannel/ComposerOmnichannelInquiry.tsx, apps/meteor/client/views/room/composer/ComposerOmnichannel/ComposerOmnichannelJoin.tsx
Normalized error-to-string conversion before dispatching toast messages in inquiry take and join handlers.
Omnichannel Chat Mutations
apps/meteor/client/views/room/composer/ComposerOmnichannel/hooks/useResumeChatOnHoldMutation.ts
Updated mutation onError to convert unknown errors to string messages for toast dispatch.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

type: bug

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: converting Error objects to string messages when dispatching toast notifications, which is consistently applied across seven files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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


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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/meteor/client/views/room/composer/ComposerJoinWithPassword.tsx`:
- Line 30: The toast fallback should handle structured API error objects instead
of blindly String(error); in the ComposerJoinWithPassword handler where
dispatchToastMessage is called, detect if the caught value is a plain object
with fields like errorType and error (or message) and extract a readable message
(e.g., `${error.errorType}: ${error.error}` or error.message) before passing to
dispatchToastMessage; update the fallback branch that currently uses
String(error) to build and pass a descriptive string when the error is an
object, leaving existing Error-instance handling intact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b9d70430-b6a8-4d04-b218-74e3527263ca

📥 Commits

Reviewing files that changed from the base of the PR and between 6a49770 and b385de2.

📒 Files selected for processing (7)
  • apps/meteor/client/hooks/useClipboardWithToast.ts
  • apps/meteor/client/views/room/composer/ComposerJoinWithPassword.tsx
  • apps/meteor/client/views/room/composer/ComposerMessage.tsx
  • apps/meteor/client/views/room/composer/ComposerOmnichannel/ComposerOmnichannelInquiry.tsx
  • apps/meteor/client/views/room/composer/ComposerOmnichannel/ComposerOmnichannelJoin.tsx
  • apps/meteor/client/views/room/composer/ComposerOmnichannel/hooks/useResumeChatOnHoldMutation.ts
  • apps/meteor/client/views/room/composer/ComposerReadOnly.tsx
📜 Review details
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/client/views/room/composer/ComposerMessage.tsx
  • apps/meteor/client/hooks/useClipboardWithToast.ts
  • apps/meteor/client/views/room/composer/ComposerOmnichannel/hooks/useResumeChatOnHoldMutation.ts
  • apps/meteor/client/views/room/composer/ComposerOmnichannel/ComposerOmnichannelInquiry.tsx
  • apps/meteor/client/views/room/composer/ComposerJoinWithPassword.tsx
  • apps/meteor/client/views/room/composer/ComposerReadOnly.tsx
  • apps/meteor/client/views/room/composer/ComposerOmnichannel/ComposerOmnichannelJoin.tsx
🧠 Learnings (14)
📓 Common learnings
Learnt from: smirk-dev
Repo: RocketChat/Rocket.Chat PR: 39625
File: apps/meteor/app/api/server/v1/push.ts:85-97
Timestamp: 2026-03-14T14:58:58.834Z
Learning: In RocketChat/Rocket.Chat, the `push.token` POST/DELETE endpoints in `apps/meteor/app/api/server/v1/push.ts` were already migrated to the chained router API pattern on `develop` prior to PR `#39625`. `cleanTokenResult` (which strips `authToken` and returns `PushTokenResult`) and `isPushTokenPOSTProps`/`isPushTokenDELETEProps` validators already exist on `develop`. PR `#39625` only migrates `push.get` and `push.info` to the chained pattern. Do not flag `cleanTokenResult` or `PushTokenResult` as newly introduced behavior-breaking changes when reviewing this PR.
📚 Learning: 2026-02-24T19:16:35.307Z
Learnt from: sampaiodiego
Repo: RocketChat/Rocket.Chat PR: 39003
File: apps/meteor/client/lib/chats/flows/sendMessage.ts:39-45
Timestamp: 2026-02-24T19:16:35.307Z
Learning: In apps/meteor/client/lib/chats/flows/sendMessage.ts, when sdk.call('sendMessage', ...) throws an error, the message is intentionally left with temp: true (not deleted or cleaned up) to support a future retry UI feature. This allows users to retry sending failed messages rather than losing them.

Applied to files:

  • apps/meteor/client/views/room/composer/ComposerMessage.tsx
  • apps/meteor/client/views/room/composer/ComposerOmnichannel/hooks/useResumeChatOnHoldMutation.ts
  • apps/meteor/client/views/room/composer/ComposerOmnichannel/ComposerOmnichannelInquiry.tsx
  • apps/meteor/client/views/room/composer/ComposerReadOnly.tsx
  • apps/meteor/client/views/room/composer/ComposerOmnichannel/ComposerOmnichannelJoin.tsx
📚 Learning: 2026-03-11T22:04:20.529Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 39545
File: apps/meteor/client/views/room/body/hooks/useHasNewMessages.ts:59-61
Timestamp: 2026-03-11T22:04:20.529Z
Learning: In `apps/meteor/client/views/room/body/hooks/useHasNewMessages.ts`, the `msg.u._id === uid` early-return in the `streamNewMessage` handler is intentional: the "New messages" indicator is designed to notify about messages from other users only. Self-sent messages — including those sent from a different session/device — are always skipped, by design. Do not flag this as a multi-session regression.

Applied to files:

  • apps/meteor/client/views/room/composer/ComposerMessage.tsx
  • apps/meteor/client/views/room/composer/ComposerOmnichannel/hooks/useResumeChatOnHoldMutation.ts
  • apps/meteor/client/views/room/composer/ComposerJoinWithPassword.tsx
  • apps/meteor/client/views/room/composer/ComposerReadOnly.tsx
📚 Learning: 2026-01-17T01:51:47.764Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38219
File: packages/core-typings/src/cloud/Announcement.ts:5-6
Timestamp: 2026-01-17T01:51:47.764Z
Learning: In packages/core-typings/src/cloud/Announcement.ts, the AnnouncementSchema.createdBy field intentionally overrides IBannerSchema.createdBy (object with _id and optional username) with a string enum ['cloud', 'system'] to match existing runtime behavior. This is documented as technical debt with a FIXME comment at apps/meteor/app/cloud/server/functions/syncWorkspace/handleCommsSync.ts:53 and should not be flagged as an error until the runtime behavior is corrected.

Applied to files:

  • apps/meteor/client/views/room/composer/ComposerMessage.tsx
  • apps/meteor/client/views/room/composer/ComposerOmnichannel/hooks/useResumeChatOnHoldMutation.ts
  • apps/meteor/client/views/room/composer/ComposerJoinWithPassword.tsx
  • apps/meteor/client/views/room/composer/ComposerReadOnly.tsx
📚 Learning: 2026-04-10T22:42:05.539Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 40075
File: apps/meteor/client/views/room/modals/FileUploadModal/FileUploadModal.tsx:69-71
Timestamp: 2026-04-10T22:42:05.539Z
Learning: In `apps/meteor/client/views/room/modals/FileUploadModal/FileUploadModal.tsx`, the submit handler converts an empty/whitespace-only description to `undefined` (`description?.trim() || undefined`) intentionally. All downstream image-rendering components (`AttachmentImage`, `ImagePreview`, `ImageItem`, `ImageGallery`) default `undefined` alt to `''`, so the `<img alt="">` attribute is always present. Do not flag this `undefined` conversion as a bug preventing alt text from being cleared.

Applied to files:

  • apps/meteor/client/views/room/composer/ComposerMessage.tsx
  • apps/meteor/client/views/room/composer/ComposerOmnichannel/ComposerOmnichannelInquiry.tsx
  • apps/meteor/client/views/room/composer/ComposerJoinWithPassword.tsx
  • apps/meteor/client/views/room/composer/ComposerReadOnly.tsx
  • apps/meteor/client/views/room/composer/ComposerOmnichannel/ComposerOmnichannelJoin.tsx
📚 Learning: 2026-03-27T14:52:56.865Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 39892
File: apps/meteor/client/views/room/contextualBar/Threads/Thread.tsx:150-155
Timestamp: 2026-03-27T14:52:56.865Z
Learning: In Rocket.Chat, there are two different `ModalBackdrop` components with different prop APIs. During review, confirm the import source: (1) `rocket.chat/fuselage` `ModalBackdrop` uses `ModalBackdropProps` based on `BoxProps` (so it supports `onClick` and other Box/DOM props) and does not have an `onDismiss` prop; (2) `rocket.chat/ui-client` `ModalBackdrop` uses a narrower props interface like `{ children?: ReactNode; onDismiss?: () => void }` and handles Escape keypress and outside mouse-up, and it does not forward arbitrary DOM props such as `onClick`. Flag mismatched props (e.g., `onDismiss` passed to the fuselage component or `onClick` passed to the ui-client component) and ensure the usage matches the correct component being imported.

Applied to files:

  • apps/meteor/client/views/room/composer/ComposerMessage.tsx
  • apps/meteor/client/views/room/composer/ComposerOmnichannel/ComposerOmnichannelInquiry.tsx
  • apps/meteor/client/views/room/composer/ComposerJoinWithPassword.tsx
  • apps/meteor/client/views/room/composer/ComposerReadOnly.tsx
  • apps/meteor/client/views/room/composer/ComposerOmnichannel/ComposerOmnichannelJoin.tsx
📚 Learning: 2026-02-10T16:32:42.586Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38528
File: apps/meteor/client/startup/roles.ts:14-14
Timestamp: 2026-02-10T16:32:42.586Z
Learning: In Rocket.Chat's Meteor client code, DDP streams use EJSON and Date fields arrive as Date objects; do not manually construct new Date() in stream handlers (for example, in sdk.stream()). Only REST API responses return plain JSON where dates are strings, so implement explicit conversion there if needed. Apply this guidance to all TypeScript files under apps/meteor/client to ensure consistent date handling in DDP streams and REST responses.

Applied to files:

  • apps/meteor/client/hooks/useClipboardWithToast.ts
  • apps/meteor/client/views/room/composer/ComposerOmnichannel/hooks/useResumeChatOnHoldMutation.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/client/hooks/useClipboardWithToast.ts
  • apps/meteor/client/views/room/composer/ComposerOmnichannel/hooks/useResumeChatOnHoldMutation.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/client/hooks/useClipboardWithToast.ts
  • apps/meteor/client/views/room/composer/ComposerOmnichannel/hooks/useResumeChatOnHoldMutation.ts
📚 Learning: 2026-04-14T21:10:31.855Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 36292
File: apps/meteor/client/hooks/useHasValidLocationHash.ts:7-12
Timestamp: 2026-04-14T21:10:31.855Z
Learning: When reviewing files in apps/meteor/client/hooks/, do not treat JSDoc-style comments on React hooks (especially exported hooks) as a violation of any “avoid code comments in implementation” guideline. It’s acceptable to use JSDoc to document the public API of exported hooks (e.g., parameter/return types, intended usage), as long as it documents behavior/contracts rather than adding narrative implementation comments.

Applied to files:

  • apps/meteor/client/hooks/useClipboardWithToast.ts
📚 Learning: 2026-03-03T11:11:48.541Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39230
File: apps/meteor/app/api/server/v1/chat.ts:214-222
Timestamp: 2026-03-03T11:11:48.541Z
Learning: In apps/meteor/server/lib/moderation/reportMessage.ts, the reportMessage function validates that description is not empty or whitespace-only with `if (!description.trim())`. When migrating the chat.reportMessage endpoint to OpenAPI, adding minLength validation to the schema preserves this existing behavior.

Applied to files:

  • apps/meteor/client/views/room/composer/ComposerOmnichannel/hooks/useResumeChatOnHoldMutation.ts
📚 Learning: 2026-04-17T17:38:12.974Z
Learnt from: d-gubert
Repo: RocketChat/Rocket.Chat PR: 39858
File: packages/ui-kit/src/interactions/UserInteraction.ts:33-33
Timestamp: 2026-04-17T17:38:12.974Z
Learning: In RocketChat/Rocket.Chat (`packages/ui-kit/src/interactions/UserInteraction.ts`), `ViewSubmitUserInteraction` and `ViewClosedUserInteraction` intentionally do NOT include `rid` when the interaction originates from a **modal** surface. Modals are not scoped to a room, so no room id is available in that context. The `rid?: string` field is optional to support the contextual bar surface (where room context exists) while remaining absent for modals. Do not flag the absence of `rid` in modal viewSubmit/viewClosed interactions as a missing-context bug.

Applied to files:

  • apps/meteor/client/views/room/composer/ComposerReadOnly.tsx
  • apps/meteor/client/views/room/composer/ComposerOmnichannel/ComposerOmnichannelJoin.tsx
📚 Learning: 2026-04-17T18:33:24.670Z
Learnt from: d-gubert
Repo: RocketChat/Rocket.Chat PR: 39858
File: apps/meteor/tests/e2e/apps/uikit-interactions.spec.ts:123-151
Timestamp: 2026-04-17T18:33:24.670Z
Learning: In RocketChat/Rocket.Chat (`apps/meteor/tests/e2e/apps/uikit-interactions.spec.ts`), `executeBlockActionHandler` invocations originating from a **modal** surface intentionally do NOT include a `block_action_room` (room property) in the interaction payload. Modals are not scoped to a room, so no room id is available in that context. Do not flag the absence of a room assertion in the modal block-action test as a missing coverage bug; instead, document it explicitly with a `test.step` asserting the room entry is `undefined`.

Applied to files:

  • apps/meteor/client/views/room/composer/ComposerReadOnly.tsx
📚 Learning: 2025-10-28T16:53:42.761Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 37205
File: ee/packages/federation-matrix/src/FederationMatrix.ts:296-301
Timestamp: 2025-10-28T16:53:42.761Z
Learning: In the Rocket.Chat federation-matrix integration (ee/packages/federation-matrix/), the createRoom method from rocket.chat/federation-sdk will support a 4-argument signature (userId, roomName, visibility, displayName) in newer versions. Code using this 4-argument call is forward-compatible with planned library updates and should not be flagged as an error.

Applied to files:

  • apps/meteor/client/views/room/composer/ComposerReadOnly.tsx
🔇 Additional comments (6)
apps/meteor/client/hooks/useClipboardWithToast.ts (1)

12-12: LGTM: the toast payload is now stringified.

This avoids passing the raw Error object into the toast dispatcher for clipboard failures.

apps/meteor/client/views/room/composer/ComposerOmnichannel/ComposerOmnichannelInquiry.tsx (1)

38-38: LGTM: error toast message normalization is correct here.

The caught Error is converted to its message before dispatching the toast.

apps/meteor/client/views/room/composer/ComposerOmnichannel/hooks/useResumeChatOnHoldMutation.ts (1)

29-29: LGTM: mutation errors now render readable toast text.

The toast dispatcher receives a string instead of the Error object.

apps/meteor/client/views/room/composer/ComposerMessage.tsx (1)

37-37: LGTM: both composer failure paths now dispatch string messages.

The join path preserves its rethrow behavior, and the send path preserves its existing handled-error behavior.

Also applies to: 64-64

apps/meteor/client/views/room/composer/ComposerOmnichannel/ComposerOmnichannelJoin.tsx (1)

25-25: LGTM: the omnichannel join toast now receives a string.

This matches the intended normalization pattern for Error instances.

apps/meteor/client/views/room/composer/ComposerReadOnly.tsx (1)

22-22: LGTM: read-only join errors are now toast-safe for Error instances.

The mutation error path now passes a string message to the dispatcher.

Comment thread apps/meteor/client/views/room/composer/ComposerJoinWithPassword.tsx Outdated
@coderabbitai coderabbitai Bot removed the type: bug label Apr 21, 2026
@Naetiksoni08
Copy link
Copy Markdown
Contributor Author

Hey, just a gentle ping on this PR! 😊 I know everyone's busy. Happy to address any feedback or make changes if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant