Skip to content

Commit

Permalink
Handle run/linting failures
Browse files Browse the repository at this point in the history
  • Loading branch information
AydinHassan committed Jan 25, 2024
1 parent 753841d commit a220a95
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
10 changes: 8 additions & 2 deletions assets/components/Online/ExerciseVerify.vue
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,12 @@ const verifySolution = () => {
</template>
<template #body>
<div class="">
<TabGroup v-if="programRunResult && programRunResult.runs.length > 1">
<template v-if="programRunResult && programRunResult.success === false">
<h2 class="mb-2 pt-0 font-mono text-lg text-[#E91E63]">Your program could not be executed, there was a syntax error</h2>
<pre class="mb-4 rounded-none border-none p-0 whitespace-pre-wrap"><code class="language-shell hljs shell block rounded-lg p-4 text-sm">{{programRunResult.failure.reason}}</code></pre>
</template>
<TabGroup v-else-if="programRunResult && programRunResult.runs.length > 1">
<TabList className="flex justify-center border-b border-solid border-gray-600">
<Tab as="template" v-slot="{ selected }" v-for="(run, i) in programRunResult.runs" :key="i">
<button
Expand All @@ -195,6 +200,7 @@ const verifySolution = () => {
<div class="flex justify-end">
<button
type="button"
v-show="programRunResult.success === true"
class="inline-flex w-full items-center justify-center rounded-full border border-transparent bg-pink-600 px-8 py-2 text-base font-medium text-white shadow-sm hover:bg-pink-700 focus:outline-none focus:ring focus:ring-pink-800 sm:ml-3 sm:w-auto sm:text-sm"
@click="runSolution"
>
Expand All @@ -205,4 +211,4 @@ const verifySolution = () => {
</template>
</Modal>
</Transition>
</template>
</template>
8 changes: 4 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions src/Action/Online/RunExercise.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PhpSchool\PhpWorkshop\Event\CgiExecuteEvent;
use PhpSchool\PhpWorkshop\Event\CliExecuteEvent;
use PhpSchool\PhpWorkshop\Event\Event;
use PhpSchool\PhpWorkshop\Exception\CouldNotRunException;
use PhpSchool\PhpWorkshop\Input\Input;
use PhpSchool\PhpWorkshop\Output\BufferedOutput;
use PhpSchool\Website\Action\JsonUtils;
Expand Down Expand Up @@ -60,12 +61,19 @@ public function __invoke(
$this->collectRunInfo($event, $output);
});

$result = $workshop->getExerciseDispatcher()->run(
$exercise,
new Input($workshop->getCode(), ['program' => $project->getEntryPoint()->getAbsolutePath()]),
$output
);

try {
$result = $workshop->getExerciseDispatcher()->run(
$exercise,
new Input($workshop->getCode(), ['program' => $project->getEntryPoint()->getAbsolutePath()]),
$output
);
} catch (CouldNotRunException $e) {
return $this->withJson([
'success' => false,
'failure' => $e->getFailure()->toArray(),
], $response);
}

$data = [
'runs' => $this->runInfo,
Expand Down

0 comments on commit a220a95

Please sign in to comment.