99import { Clock , Code2 , Play } from "lucide-react" ;
1010import LanguageSelection from "./editor-view/language-selection" ;
1111import { Button } from "@/components/ui/button" ;
12- import { ExecutionResult , Language , Output } from "@/@types" ;
12+ import { ExecutionResult , Language } from "@/@types" ;
1313import { useState , useTransition } from "react" ;
1414import { executeCodeAction } from "../_actions/execute" ;
1515import { 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