close
Skip to content

fix(editor): remove console.log/error from replaceCodeWithText and surface errors properly#8963

Open
selenaalpha77-sketch wants to merge 1 commit intomakeplane:previewfrom
selenaalpha77-sketch:fix/editor-replace-code-block-remove-console
Open

fix(editor): remove console.log/error from replaceCodeWithText and surface errors properly#8963
selenaalpha77-sketch wants to merge 1 commit intomakeplane:previewfrom
selenaalpha77-sketch:fix/editor-replace-code-block-remove-console

Conversation

@selenaalpha77-sketch
Copy link
Copy Markdown

What's the bug?

replaceCodeWithText in packages/editor/src/core/extensions/code/utils/replace-code-block-with-text.ts has two silent failure paths that should not exist in production code.

  1. 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.

  2. console.error("Invalid range…") followed by return — an invalid position range (negative from, out-of-bounds to, 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

  • The "no code block found" path is a legitimate no-op; replaced console.log + return with a plain early return and a short inline comment.
  • The invalid-range path is an unexpected error; replaced console.error + return with throw new Error(...) so the keyboard-shortcut handler (and any future error boundary) can decide how to surface it.
  • Removed the outer try/catch that was turning every thrown error back into a silent console.error; errors now propagate to the caller.

…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.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 27, 2026

Warning

Rate limit exceeded

@selenaalpha77-sketch has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 0 minutes and 44 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4d5878ac-a895-490d-88a9-c2c2eb217c39

📥 Commits

Reviewing files that changed from the base of the PR and between a40e064 and 015e03f.

📒 Files selected for processing (1)
  • packages/editor/src/core/extensions/code/utils/replace-code-block-with-text.ts
✨ 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.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


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.

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.

2 participants