Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/pages/EditorComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
height: "30vh",
padding: "1rem",
},
overflow: "auto",
}));

Check failure on line 60 in src/pages/EditorComponent.js

View workflow job for this annotation

GitHub Actions / Performs linting on the application

Duplicate key 'overflow'

const WelcomeText = styled("span")(({ theme }) => ({
color: theme.palette.text.primary,
Expand Down Expand Up @@ -176,6 +177,10 @@
const data = await response.json();
const submissionId = data["token"];

const decodeFormat = (data) => {
return atob(data).split("\n");
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The decodeFormat function doesn't handle null or undefined input. When data.stderr or data.compile_output is null/undefined (which can happen with Judge0 API responses), calling atob(data) will throw an error. Add a guard to check if data exists before decoding: return data ? atob(data).split(\"\\n\") : [];

Suggested change
return atob(data).split("\n");
return data ? atob(data).split("\n") : [];

Copilot uses AI. Check for mistakes.
}
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The decodeFormat function is defined inside the async callback function, causing it to be recreated on every code execution. Consider moving this function outside the runCode function or to the top level of the component to avoid unnecessary function recreation.

Copilot uses AI. Check for mistakes.

setTimeout(() => {
fetch(
`${judge0SubmitUrl}/${submissionId}?base64_encoded=true&fields=*`,
Expand All @@ -190,13 +195,18 @@
.then((response) => response.json())
.then((data) => {
if (!data.stdout) {
enqueueSnackbar("Please check the code", { variant: "error" });
setOutput(data.message);
return;
if(data.stderr) {
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after 'if' keyword. Should be if (data.stderr) to maintain consistent code formatting throughout the file.

Suggested change
if(data.stderr) {
if (data.stderr) {

Copilot uses AI. Check for mistakes.
enqueueSnackbar("Please check the code", { variant: "error" });
setOutput(decodeFormat(data.stderr));
return;
}
else {
enqueueSnackbar("Please check the code", { variant: "error" });
setOutput(decodeFormat(data.compile_output));
return;
}
}
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The else block assumes compile_output exists, but doesn't verify it. If both stderr and compile_output are null/undefined, this will cause an error when decodeFormat is called. Consider adding a check: else if (data.compile_output) and handle the case where neither exists.

Copilot uses AI. Check for mistakes.
const decodedOutput = atob(data.stdout);
const formattedData = decodedOutput.split("\n");
setOutput(formattedData);
setOutput(decodeFormat(data.stdout));
})
.catch((error) => {
enqueueSnackbar("Error retrieving output: " + error.message, {
Expand Down
Loading