fix(editor): remove console.log/error from replaceCodeWithText and surface errors properly#8963
Conversation
…rface errors properly
replaceCodeWithText() had two silent failure paths:
1. console.log("No code block to replace.") — logs and returns silently when
no code block is found in the selection, making debugging impossible and
producing noisy browser console output in production.
2. console.error("Invalid range…") followed by return — swallows an invalid-
range condition silently instead of surfacing it.
Replace both with proper control flow: an early return (no-op) when there is
genuinely nothing to do, and throw so callers can handle real errors.
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
evan seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
What's the bug?
replaceCodeWithTextinpackages/editor/src/core/extensions/code/utils/replace-code-block-with-text.tshas two silent failure paths that should not exist in production code.console.log("No code block to replace.")— when no code block is found in the current selection the function logs to the browser console and returns silently. This produces noisy output in production and gives callers no way to distinguish a real error from an expected no-op.console.error("Invalid range…")followed byreturn— an invalid position range (negativefrom, out-of-boundsto, or inverted range) is printed to the console and then silently swallowed. The editor ends up in an undefined state and the caller has no indication that anything went wrong.Fix
console.log+ return with a plain earlyreturnand a short inline comment.console.error+ return withthrow new Error(...)so the keyboard-shortcut handler (and any future error boundary) can decide how to surface it.try/catchthat was turning every thrown error back into a silentconsole.error; errors now propagate to the caller.