docs/solutions/logic-errors/2026-04-17-code-block-highlight-fallback-must-not-throw-through-debug-plugin.md
The code block docs page crashed in browser when one highlighted sample failed to tokenize.
The specific repro was /docs/code-block: instead of rendering the page and
degrading one block, the route hit the docs error boundary.
PlateError: [CODE_HIGHLIGHT] Error: Could not highlight with Highlight.jssetCodeBlockToDecorations already made
highlight failures safeKeep the plaintext fallback, but stop using editor.api.debug.error(...) inside
the highlight catch path.
debug.error throws in dev by design, which means this code:
try {
highlighted = lowlight.highlight(effectiveLanguage, text);
} catch (error) {
editor.api.debug.error(error, 'CODE_HIGHLIGHT');
highlighted = { value: [] };
}
never actually reached the fallback.
Use a non-throwing warning instead:
try {
highlighted = lowlight.highlight(effectiveLanguage, text);
} catch (error) {
editor.api.debug.warn(
`Could not highlight with Highlight.js for language "${effectiveLanguage}". Falling back to plaintext`,
'CODE_HIGHLIGHT',
error
);
highlighted = { value: [] };
}
Update the unit test to assert warning-based fallback for registered languages that fail to highlight.
The code already wanted graceful degradation. The real bug was that the logging lane overruled the fallback lane.
With debug.warn, the editor still records the failure in dev, but it no
longer converts a recoverable highlight problem into a fatal route crash.
debug.error that never throws can hide a production-facing
or dev-facing crash path.