[fixes issue 201]: shows errors while running code in output#202
[fixes issue 201]: shows errors while running code in output#202Prathamesh0901 wants to merge 4 commits into
Conversation
|
@Prathamesh0901 is attempting to deploy a commit to the Dhanush Nehru's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull Request Overview
This PR enhances error reporting in the code editor by displaying compilation errors and stderr output in the output panel instead of just showing a generic snackbar notification. The changes extract error details from the Judge0 API response (stderr and compile_output) and display them in a user-friendly format.
Key changes:
- Added auto-scrolling to the output panel for better visibility of long error messages
- Refactored output decoding logic into a reusable function
- Enhanced error handling to differentiate between runtime errors (stderr) and compilation errors (compile_output)
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| const submissionId = data["token"]; | ||
|
|
||
| const decodeFormat = (data) => { | ||
| return atob(data).split("\n"); |
There was a problem hiding this comment.
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\") : [];
| return atob(data).split("\n"); | |
| return data ? atob(data).split("\n") : []; |
| enqueueSnackbar("Please check the code", { variant: "error" }); | ||
| setOutput(data.message); | ||
| return; | ||
| if(data.stderr) { |
There was a problem hiding this comment.
Missing space after 'if' keyword. Should be if (data.stderr) to maintain consistent code formatting throughout the file.
| if(data.stderr) { | |
| if (data.stderr) { |
| if(data.stderr) { | ||
| 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; | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
|
Please solve the lint and copilot issues @Prathamesh0901 |
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| const decodeFormat = (data) => { | ||
| return data?atob(data).split("\n"):[]; | ||
| } |
There was a problem hiding this comment.
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.
This reverts commit d050e97.
Resolves #[Issue Number if there]
PR Fixes:
Checklist before requesting a review
mainbranchnpm run lint:fixlocallyCurrently, there are no compilation or output errors shown in the editor. The only thing is a snackbar which is generic, the judge0 api provides compilation or any errors in the api, I have added them in the output section.
Current
Modified