Skip to content

Commit 343f9ca

Browse files
feat(runtime): add fatalError and onError callback propagation
Agent-Logs-Url: https://github.com/ut-code/my-code/sessions/3499a4d7-2b75-4046-b6d5-24912d4eaf0a Co-authored-by: na-trium-144 <100704180+na-trium-144@users.noreply.github.com>
1 parent 72977c7 commit 343f9ca

23 files changed

Lines changed: 228 additions & 23877 deletions

app/terminal/exec.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { useEmbedContext } from "./embedContext";
1313
import clsx from "clsx";
1414
import { LangConstants } from "@my-code/runtime/languages";
1515
import { useRuntime } from "@my-code/runtime/context";
16+
import { captureException } from "@sentry/nextjs";
1617
import { MinMaxButton, Modal } from "./modal";
1718

1819
interface ExecProps {
@@ -68,8 +69,15 @@ export function ExecFile(props: ExecProps) {
6869
`Language ${props.language.originalLang} does not have a runtime environment.`
6970
);
7071
}
72+
const handleRuntimeError = useCallback((error: unknown) => {
73+
if (error instanceof Error) {
74+
captureException(error);
75+
return;
76+
}
77+
captureException(new Error(String(error)));
78+
}, []);
7179
const { ready, runFiles, getCommandlineStr, runtimeInfo, interrupt } =
72-
useRuntime(props.language.runtime);
80+
useRuntime(props.language.runtime, { onError: handleRuntimeError });
7381

7482
// ユーザーがクリックした時(triggered) && ランタイムが準備できた時に、実際にinitCommandを実行する(executing)
7583
const [executionState, setExecutionState] = useState<

app/terminal/repl.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { useEmbedContext } from "./embedContext";
1717
import { LangConstants } from "@my-code/runtime/languages";
1818
import clsx from "clsx";
1919
import { InlineCode } from "@/markdown/codeBlock";
20+
import { captureException } from "@sentry/nextjs";
2021
import {
2122
emptyMutex,
2223
ReplCommand,
@@ -39,6 +40,9 @@ export function writeOutput(
3940
case "error":
4041
term.writeln(chalk.red(message));
4142
break;
43+
case "fatalError":
44+
term.writeln(chalk.bgRed.white(message));
45+
break;
4246
case "trace":
4347
term.writeln(chalk.blue.italic(message));
4448
break;
@@ -86,6 +90,13 @@ export function ReplTerminal({
8690
`Language ${language.originalLang} does not have a runtime environment.`
8791
);
8892
}
93+
const handleRuntimeError = useCallback((error: unknown) => {
94+
if (error instanceof Error) {
95+
captureException(error);
96+
return;
97+
}
98+
captureException(new Error(String(error)));
99+
}, []);
89100

90101
const {
91102
ready: runtimeReady,
@@ -95,7 +106,7 @@ export function ReplTerminal({
95106
checkSyntax,
96107
splitReplExamples,
97108
runtimeInfo,
98-
} = useRuntime(language.runtime);
109+
} = useRuntime(language.runtime, { onError: handleRuntimeError });
99110
const { tabSize, prompt, promptMore, returnPrefix } = language;
100111
if (!prompt) {
101112
console.warn(`prompt not defined for language: ${language}`);

0 commit comments

Comments
 (0)