Skip to content

Commit f54ad9b

Browse files
committed
fix(challenges): don't throw error for bad SQL code
1 parent 3cfae78 commit f54ad9b

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

  • app/(app)/challenges/[id]/_components/sql-editor

app/(app)/challenges/[id]/_components/sql-editor/editor.tsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,23 @@ export default function SQLEditor({
2929
"sql-formatter"
3030
);
3131

32-
const currentCode = codeMirrorRef.current?.view?.state.doc.toString() ?? "";
33-
const formattedCode = formatDialect(currentCode, {
34-
dialect: formatterSqlite,
35-
keywordCase: "upper",
36-
});
37-
38-
codeMirrorRef.current?.view?.dispatch({
39-
changes: { from: 0, to: currentCode.length, insert: formattedCode },
40-
});
41-
42-
toast.success("成功格式化 SQL 程式碼");
32+
try {
33+
const currentCode = codeMirrorRef.current?.view?.state.doc.toString() ?? "";
34+
const formattedCode = formatDialect(currentCode, {
35+
dialect: formatterSqlite,
36+
keywordCase: "upper",
37+
});
38+
39+
codeMirrorRef.current?.view?.dispatch({
40+
changes: { from: 0, to: currentCode.length, insert: formattedCode },
41+
});
42+
43+
toast.success("成功格式化 SQL 程式碼");
44+
} catch (error) {
45+
toast.error("無法格式化 SQL 程式碼", {
46+
description: error instanceof Error ? error.message : undefined,
47+
});
48+
}
4349
};
4450

4551
return (

0 commit comments

Comments
 (0)