authorgravatar for 110hqc@gmail.comQiaochu Hu <110hqc@gmail.com> 2026-03-13 03:35:21+08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-03-12 12:35:21-07:00
logb496ae839529b910d5a35e9e05d6be704a41b5a5
treebfa30be1c54a375affeaebc9f4896dc265e011a3
parent724f54c2c1f4a1efcd7423a5ff0e3db625629815
signature Signed by PGP key B5690EEEBB952194

fix: add error logging for code highlighting failures (#951)


1 files changed, 7 insertions(+), 6 deletions(-)

apps/web/src/components/ChatMarkdown.tsx+7-6
......@@ -1,8 +1,4 @@
1import {
2 getSharedHighlighter,
3 type DiffsHighlighter,
4 type SupportedLanguages,
5} from "@pierre/diffs";
1import { DiffsHighlighter, getSharedHighlighter, SupportedLanguages } from "@pierre/diffs";
62import { CheckIcon, CopyIcon } from "lucide-react";
73import React, {
84 Children,
......@@ -213,7 +209,12 @@ function SuspenseShikiCodeBlock({
213209 const highlightedHtml = useMemo(() => {
214210 try {
215211 return highlighter.codeToHtml(code, { lang: language, theme: themeName });
216 } catch {
212 } catch (error) {
213 // Log highlighting failures for debugging while falling back to plain text
214 console.warn(
215 `Code highlighting failed for language "${language}", falling back to plain text.`,
216 error instanceof Error ? error.message : error,
217 );
217218 // If highlighting fails for this language, render as plain text
218219 return highlighter.codeToHtml(code, { lang: "text", theme: themeName });
219220 }