Skip to content

Commit 718301f

Browse files
[fix] fixed unexpected issue which is on the error sections 🥖
1 parent 3a8a73c commit 718301f

2 files changed

Lines changed: 25 additions & 36 deletions

File tree

websites/src/app/_actions/execute.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,15 @@ export async function executeCodeAction(input: Input): Promise<Output> {
1919
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2020
} catch (error: any) {
2121
const end = performance.now();
22-
const responseTime = Math.round(end - start);
2322

24-
// Safer extraction of error message
25-
const errorMessage =
26-
error?.response?.data?.details || "Unknown error occurred";
23+
const output =
24+
error?.response?.data?.details ||
25+
error?.message ||
26+
"Unknown error occurred";
2727

28-
throw new Error(
29-
JSON.stringify({
30-
output: errorMessage,
31-
responseTime,
32-
})
33-
);
28+
return {
29+
output,
30+
responseTime: Math.round(end - start),
31+
};
3432
}
3533
}

websites/src/app/_components/code-input.tsx

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { Clock, Code2, Play } from "lucide-react";
1010
import LanguageSelection from "./editor-view/language-selection";
1111
import { Button } from "@/components/ui/button";
12-
import { ExecutionResult, Language, Output } from "@/@types";
12+
import { ExecutionResult, Language } from "@/@types";
1313
import { useState, useTransition } from "react";
1414
import { executeCodeAction } from "../_actions/execute";
1515
import { CodeEditor } from "./editor-view/code-editor";
@@ -25,6 +25,7 @@ export default function CodeInput() {
2525

2626
const executeCode = async () => {
2727
if (!code.trim()) return;
28+
2829
startExecution(async () => {
2930
setExecutionResult({
3031
status: "running",
@@ -34,33 +35,23 @@ export default function CodeInput() {
3435
},
3536
language: selectedLanguage,
3637
});
37-
try {
38-
const data = await executeCodeAction({
39-
language: selectedLanguage,
40-
code,
41-
});
42-
setExecutionResult({
43-
status: "success",
44-
results: {
45-
output: data.output,
46-
responseTime: data.responseTime,
47-
},
48-
language: selectedLanguage,
49-
});
50-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
51-
} catch (err: any) {
52-
const error = JSON.parse(err.message) as Output;
53-
setExecutionResult({
54-
status: "error",
55-
results: {
56-
output: error.output,
57-
responseTime: error.responseTime,
58-
},
59-
language: selectedLanguage,
60-
});
61-
}
38+
39+
const result = await executeCodeAction({
40+
language: selectedLanguage,
41+
code,
42+
});
43+
44+
// Use a simple heuristic: if output contains "Error" or has failed response
45+
const isError = result.output?.toLowerCase().includes("error");
46+
47+
setExecutionResult({
48+
status: isError ? "error" : "success",
49+
results: result,
50+
language: selectedLanguage,
51+
});
6252
});
6353
};
54+
6455
return (
6556
<>
6657
<Card className="h-fit bg-white/5 backdrop-blur-sm border border-white/10 text-white">

0 commit comments

Comments
 (0)