fix(react/runtime): allow lynx.reportError() to receive string as arg#1560
Conversation
|
📝 WalkthroughWalkthroughExpands 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Suggested reviewers
Poem
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 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
There was a problem hiding this comment.
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 safelyJSON.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 siteNow 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 reportingAccepting 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.
📒 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)
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
React Example#4377 Bundle Size — 237.07KiB (+0.01%).d92d13e(current) vs a8ca0f0 main#4374(baseline) Bundle metrics
Bundle size by type
Bundle analysis report Branch Yradex:mts/run-on-mt/report-erro... Project dashboard Generated by RelativeCI Documentation Report issue |
Web Explorer#4370 Bundle Size — 366.68KiB (0%).d92d13e(current) vs a8ca0f0 main#4367(baseline) Bundle metrics
Bundle size by type
|
| Current #4370 |
Baseline #4367 |
|
|---|---|---|
234.68KiB |
234.68KiB |
|
100.16KiB |
100.16KiB |
|
31.84KiB |
31.84KiB |
Bundle analysis report Branch Yradex:mts/run-on-mt/report-erro... Project dashboard
Generated by RelativeCI Documentation Report issue
CodSpeed Performance ReportMerging #1560 will not alter performanceComparing Summary
|
Summary by CodeRabbit
Checklist