Skip to content

fix(react/runtime): allow lynx.reportError() to receive string as arg#1560

Merged
colinaaa merged 1 commit intolynx-family:mainfrom
Yradex:mts/run-on-mt/report-error
Aug 19, 2025
Merged

fix(react/runtime): allow lynx.reportError() to receive string as arg#1560
colinaaa merged 1 commit intolynx-family:mainfrom
Yradex:mts/run-on-mt/report-error

Conversation

@Yradex
Copy link
Copy Markdown
Collaborator

@Yradex Yradex commented Aug 19, 2025

Summary by CodeRabbit

  • New Features
    • Enhanced error reporting to accept both Error objects and plain text messages.
    • Non-standard inputs are normalized for consistent handling, improving stability.
    • Maintains existing error routing behavior while capturing more issues reliably.
    • End users may experience fewer interruptions and more informative error feedback.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).
  • Changeset added, and when a BREAKING CHANGE occurs, it needs to be clearly marked (or not required).

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Aug 19, 2025

⚠️ No Changeset found

Latest commit: d92d13e

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 Aug 19, 2025

📝 Walkthrough

Walkthrough

Expands lynx.reportError to accept Error or string in the LEPUS path of setupLynxEnv, normalizing strings into Error objects before forwarding to _ReportError with code 1101. Public method signature updated accordingly in packages/react/runtime/src/lynx/env.ts.

Changes

Cohort / File(s) Summary of edits
Lynx env error handling
packages/react/runtime/src/lynx/env.ts
Broadened lynx.reportError parameter to `Error

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

framework:React

Suggested reviewers

  • hzy
  • colinaaa

Poem

A hop, a skip, an error to string,
I nibble the stack and tidy the thing.
From text to Exception—poof!—I convert,
Then burrow it down to 1101 alert.
Ears up, code snug—thump-thump—no dirt! 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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

🧹 Nitpick comments (3)
packages/react/runtime/src/lynx/env.ts (3)

21-23: Avoid JSON.stringify for strings; use String(e) to prevent extra quotes and handle unknown values safely

JSON.stringify('oops') produces '"oops"' (with quotes). Using String(e) preserves the message and avoids JSON serialization pitfalls if a non-Error, non-string ever slips through at runtime.

Apply this minimal change:

-      const error = e instanceof Error ? e : new Error(JSON.stringify(e));
+      const error = e instanceof Error ? e : new Error(String(e));

64-66: Drop the unnecessary Error cast at the call site

Now that lynx.reportError accepts Error | string, the cast to Error is misleading and unnecessary. Passing e directly also better reflects that catch(e) can be anything.

Proposed change (outside the changed hunk):

} catch (e: any) {
  lynx.reportError(e);
  // when there is an error
  // we should perform like dataProcessor returns nothing
  // so use `{}` rather than `data`
  r = {};
}

21-23: Optional: sanitize/truncate raw string messages before reporting

Accepting arbitrary strings can forward very large payloads or PII straight to _ReportError. Consider truncating to a safe length and/or masking obvious secrets.

Example approach (outside the changed hunk):

function normalizeMessage(msg: string, max = 2000): string {
  const trimmed = msg.length > max ? msg.slice(0, max) + '…' : msg;
  // Optionally mask tokens/keys if you have patterns.
  return trimmed;
}

// usage inside reportError:
const error = e instanceof Error ? e : new Error(normalizeMessage(String(e)));

If you want, I can open a follow-up PR adding this helper with unit tests.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a8ca0f0 and d92d13e.

📒 Files selected for processing (1)
  • packages/react/runtime/src/lynx/env.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/react/runtime/src/lynx/env.ts (1)
packages/webpack/webpack-dev-transport/client/index.ts (1)
  • error (139-141)

Comment thread packages/react/runtime/src/lynx/env.ts
@codecov
Copy link
Copy Markdown

codecov Bot commented Aug 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Aug 19, 2025

React Example

#4377 Bundle Size — 237.07KiB (+0.01%).

d92d13e(current) vs a8ca0f0 main#4374(baseline)

Bundle metrics  Change 1 change
                 Current
#4377
     Baseline
#4374
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
Change  Cache Invalidation 38.51% 0%
No change  Chunks 0 0
No change  Assets 4 4
No change  Modules 158 158
No change  Duplicate Modules 64 64
No change  Duplicate Code 45.86% 45.86%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  Change 1 change Regression 1 regression
                 Current
#4377
     Baseline
#4374
No change  IMG 145.76KiB 145.76KiB
Regression  Other 91.31KiB (+0.03%) 91.28KiB

Bundle analysis reportBranch Yradex:mts/run-on-mt/report-erro...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Aug 19, 2025

Web Explorer

#4370 Bundle Size — 366.68KiB (0%).

d92d13e(current) vs a8ca0f0 main#4367(baseline)

Bundle metrics  Change 1 change
                 Current
#4370
     Baseline
#4367
No change  Initial JS 143.49KiB 143.49KiB
No change  Initial CSS 31.84KiB 31.84KiB
No change  Cache Invalidation 0% 0%
No change  Chunks 7 7
No change  Assets 7 7
Change  Modules 211(-0.47%) 212
No change  Duplicate Modules 17 17
No change  Duplicate Code 3.89% 3.89%
No change  Packages 4 4
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#4370
     Baseline
#4367
No change  JS 234.68KiB 234.68KiB
No change  Other 100.16KiB 100.16KiB
No change  CSS 31.84KiB 31.84KiB

Bundle analysis reportBranch Yradex:mts/run-on-mt/report-erro...Project dashboard


Generated by RelativeCIDocumentationReport issue

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Aug 19, 2025

CodSpeed Performance Report

Merging #1560 will not alter performance

Comparing Yradex:mts/run-on-mt/report-error (d92d13e) with main (a8ca0f0)

Summary

✅ 10 untouched benchmarks

@colinaaa colinaaa merged commit f3e9ae5 into lynx-family:main Aug 19, 2025
45 of 46 checks passed
@Yradex Yradex deleted the mts/run-on-mt/report-error branch September 11, 2025 06:48
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.

2 participants