Skip to content

Commit 1653e52

Browse files
[feat 🐱‍🏍] typescript language suggetions & improve codes and more 🔥
1 parent 50c4e8a commit 1653e52

21 files changed

Lines changed: 189 additions & 180 deletions

app.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ app.post("/run", async (req, res) => {
8484
if (stderr) {
8585
return res.status(500).json({
8686
error: "Runtime error",
87-
details: extractError(stderr),
87+
details: extractError(stderr), // TODO: need to set a extractor
8888
});
8989
}
9090
return res.status(200).json({
@@ -93,14 +93,13 @@ app.post("/run", async (req, res) => {
9393
} catch (err) {
9494
return res.status(500).json({
9595
error: "Internal Server error",
96-
details: extractError(err.message),
96+
details: extractError(err.message), // TODO: need to set a extractor
9797
});
9898
} finally {
9999
await fs.rm(tempDirInsideNodeServer, { recursive: true, force: true });
100100
}
101101
});
102102

103-
// Use PORT from environment variables, or default to 6000
104103
const PORT = process.env.PORT || 5000;
105104
app.listen(PORT, () => {
106105
console.log(`Code executor backend listening on port ${PORT}`);

docker-compose.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@ services:
22
nodejs-image:
33
build:
44
context: .
5-
dockerfile: Dockerfile.nodejs
5+
dockerfile: docker/Dockerfile.nodejs
66
image: executor-nodejs:latest
77

88
deno-image:
99
build:
1010
context: .
11-
dockerfile: Dockerfile.deno
11+
dockerfile: docker/Dockerfile.deno
1212
image: executor-deno:latest
1313

1414
python-image:
1515
build:
1616
context: .
17-
dockerfile: Dockerfile.python
17+
dockerfile: docker/Dockerfile.python
1818
image: executor-python:latest
1919

2020
java-image:
2121
build:
2222
context: .
23-
dockerfile: Dockerfile.jvm
23+
dockerfile: docker/Dockerfile.jvm
2424
image: executor-java:latest
2525

2626
nodejs-server-image:
File renamed without changes.
File renamed without changes.

utils/index.js

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,11 @@
11
/**
22
* Extracts clean error messages from Docker execution details
3-
* @param {string} details - The raw error details from Docker execution
3+
* @param {string} input - The raw error details from Docker execution
44
* @returns {string} - Clean, user-friendly error message
55
*/
6-
export function extractError(details) {
7-
if (!details || typeof details !== "string") {
8-
return "Unknown error occurred";
9-
}
6+
export function extractError(input) {
7+
const regex = /^(Command failed: docker run[\s\S]*?\/app")([\s\S]*)$/m;
108

11-
// TypeScript/Deno parsing errors
12-
const tsParseMatch = details.match(
13-
/error: The module's source code could not be parsed: (.+?) at file:/
14-
);
15-
if (tsParseMatch) {
16-
return `Syntax Error: ${tsParseMatch[1].trim()}`;
17-
}
18-
19-
// Python errors - extract from traceback
20-
const pythonErrorMatch = details.match(/(\w+Error): (.+?)(?:\n|$)/);
21-
if (pythonErrorMatch) {
22-
return `${pythonErrorMatch[1]}: ${pythonErrorMatch[2].trim()}`;
23-
}
24-
25-
// Node.js errors - extract ReferenceError, TypeError, etc.
26-
const nodeErrorMatch = details.match(/(\w+Error): (.+?)(?:\n| at)/);
27-
if (nodeErrorMatch) {
28-
return `${nodeErrorMatch[1]}: ${nodeErrorMatch[2].trim()}`;
29-
}
30-
31-
// Generic error patterns
32-
const genericErrorMatch = details.match(/error: (.+?)(?:\n|$)/i);
33-
if (genericErrorMatch) {
34-
return `Error: ${genericErrorMatch[1].trim()}`;
35-
}
36-
37-
// Fallback - try to extract any line that looks like an error
38-
const lines = details.split("\n");
39-
for (const line of lines) {
40-
const trimmed = line.trim();
41-
if (trimmed.includes("Error:") || trimmed.includes("error:")) {
42-
// Remove file paths and line numbers
43-
const cleaned = trimmed
44-
.replace(/at file:\/\/\/[^\s]+/g, "")
45-
.replace(/at Object\.<anonymous>.+/g, "")
46-
.replace(/at Module\._compile.+/g, "")
47-
.replace(/\s+/g, " ")
48-
.trim();
49-
50-
if (cleaned.length > 0) {
51-
return cleaned;
52-
}
53-
}
54-
}
55-
56-
return "Execution failed with unknown error";
9+
const match = input.match(regex);
10+
return match ? match[2] : "Unexpected error occured!";
5711
}

websites/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"perf_hooks": "^0.0.1",
2323
"react": "^19.0.0",
2424
"react-dom": "^19.0.0",
25+
"sonner": "^2.0.5",
2526
"tailwind-merge": "^3.3.1"
2627
},
2728
"devDependencies": {

websites/pnpm-lock.yaml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

websites/src/app/_actions/execute.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export async function executeCodeAction(input: Input): Promise<Output> {
1919
let end = 0;
2020
try {
2121
const response = await axios.post(`${baseUri}/run`, input);
22+
end = performance.now();
2223
responseTime = end - start;
2324

2425
return {
@@ -27,11 +28,14 @@ export async function executeCodeAction(input: Input): Promise<Output> {
2728
};
2829
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2930
} catch (error: any) {
30-
return {
31-
output: error?.response?.data.details,
31+
end = performance.now();
32+
responseTime = end - start;
33+
34+
const errorMessage = error.response.data.details as unknown as string;
35+
const response = {
36+
output: errorMessage,
3237
responseTime: Math.round(responseTime),
3338
};
34-
} finally {
35-
end = performance.now();
39+
throw new Error(JSON.stringify(response));
3640
}
3741
}

0 commit comments

Comments
 (0)