Skip to content

Commit

Permalink
Do not fail silently if JavaScript errors
Browse files Browse the repository at this point in the history
  • Loading branch information
niknetniko committed May 29, 2024
1 parent 7d84c47 commit fd673a5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
3 changes: 3 additions & 0 deletions tested/judge/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def run_command(
timeout: float | None,
command: list[str] | None = None,
stdin: str | None = None,
check: bool = False,
) -> BaseExecutionResult | None:
"""
Run a command and get the result of said command.
Expand All @@ -42,6 +43,7 @@ def run_command(
:param command: Optional, the command to execute.
:param stdin: Optional stdin for the process.
:param timeout: The max time for this command.
:param check: Raise if the command fails.
:return: The result of the execution if the command was not None.
"""
Expand All @@ -58,6 +60,7 @@ def run_command(
capture_output=True,
input=stdin,
timeout=timeout,
check=check,
)
except subprocess.TimeoutExpired as e:
return BaseExecutionResult(
Expand Down
22 changes: 10 additions & 12 deletions tested/languages/javascript/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,16 @@ def modify_solution(self, solution: Path):
assert self.config

parse_file = str(Path(__file__).parent / "parseAst.js")
try:
output = run_command(
solution.parent,
timeout=None,
command=["node", parse_file, str(solution.absolute())],
)
if output:
namings = output.stdout.strip()
with open(solution, "a") as file:
print(f"\nmodule.exports = {{{namings}}};", file=file)
except TimeoutError:
pass
output = run_command(
solution.parent,
timeout=None,
command=["node", parse_file, str(solution.absolute())],
check=True,
)
assert output, "Missing output from JavaScript's modify_solution"
namings = output.stdout.strip()
with open(solution, "a") as file:
print(f"\nmodule.exports = {{{namings}}};", file=file)

# Add strict mode to the script.
with open(solution, "r") as file:
Expand Down

0 comments on commit fd673a5

Please sign in to comment.