Skip to content

Commit

Permalink
Show exception messages in built output
Browse files Browse the repository at this point in the history
  • Loading branch information
imacrayon committed Jan 27, 2024
1 parent 4412cd7 commit 3420345
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ protected function createContentFiles($urls = '*')

$results = $this->tasks->run(...$closures);

if ($this->anyTasksFailed($results)) {
throw GenerationFailedException::withConsoleMessage("\x1B[1A\x1B[2K");
if ($message = $this->firstFailedTask($results)) {
throw GenerationFailedException::withConsoleMessage("\x1B[1A\x1B[2K".$message);
}

$this->taskResults = $this->compileTasksResults($results);
Expand All @@ -213,9 +213,9 @@ protected function createContentFiles($urls = '*')
return $this;
}

protected function anyTasksFailed($results)
protected function firstFailedTask($results)
{
return collect($results)->contains('');
return collect($results)->first(fn ($result) => is_string($result));
}

protected function compileTasksResults(array $results)
Expand Down Expand Up @@ -288,7 +288,7 @@ protected function makeContentGenerationClosures($pages, $request)
$generated = $page->generate($request);
} catch (NotGeneratedException $e) {
if ($this->shouldFail($e)) {
throw GenerationFailedException::withConsoleMessage("\x1B[1A\x1B[2K".$e->consoleMessage());
return $e->consoleMessage();
}

$errors[] = $e->consoleMessage();
Expand All @@ -300,7 +300,7 @@ protected function makeContentGenerationClosures($pages, $request)

if ($generated->hasWarning()) {
if ($this->shouldFail($generated)) {
throw GenerationFailedException::withConsoleMessage($generated->consoleMessage());
return $generated->consoleMessage();
}

$warnings[] = $generated->consoleMessage();
Expand Down

0 comments on commit 3420345

Please sign in to comment.