Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 14 additions & 3 deletions src/Framework/Actions/PostBuildTasks/GenerateBuildManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use Hyde\Facades\Config;
use Hyde\Pages\Concerns\HydePage;
use Hyde\Framework\Features\BuildTasks\PostBuildTask;
use Illuminate\Console\OutputStyle;
use Illuminate\Support\Collection;
use Throwable;

use function Hyde\unixsum_file;
use function file_put_contents;
Expand Down Expand Up @@ -79,8 +79,19 @@ protected function jsonEncodeOutput(Collection $pages): string
], JSON_PRETTY_PRINT);
}

public function setOutput(OutputStyle $output): void
public function printStartMessage(): void
{
// Disable output
// Deferred to failure handler
}

public function printFinishMessage(): void
{
// Silent
}

protected function handleExceptionReporting(Throwable $exception): void
{
$this->write("<comment>{$this->getMessage()}...</comment> ");
parent::handleExceptionReporting($exception);
}
}
19 changes: 12 additions & 7 deletions src/Framework/Features/BuildTasks/BuildTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,7 @@ public function run(?OutputStyle $output = null): int
$this->handle();
$this->printFinishMessage();
} catch (Throwable $exception) {
if ($exception instanceof BuildTaskSkippedException) {
$this->write("<bg=yellow>Skipped</>\n");
$this->write("<fg=gray> > {$exception->getMessage()}</>");
} else {
$this->write("<error>Failed</error>\n");
$this->write("<error>{$exception->getMessage()}</error>");
}
$this->handleExceptionReporting($exception);

$this->exitCode = $exception->getCode();
}
Expand Down Expand Up @@ -123,4 +117,15 @@ public function withExecutionTime(): static

return $this;
}

protected function handleExceptionReporting(Throwable $exception): void
{
if ($exception instanceof BuildTaskSkippedException) {
$this->write("<bg=yellow>Skipped</>\n");
$this->write("<fg=gray> > {$exception->getMessage()}</>");
} else {
$this->write("<error>Failed</error>\n");
$this->write("<error>{$exception->getMessage()}</error>");
}
}
}
27 changes: 27 additions & 0 deletions tests/Unit/GenerateBuildManifestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Hyde\Framework\Testing\Unit;

use Exception;
use Hyde\Framework\Actions\PostBuildTasks\GenerateBuildManifest;
use Hyde\Framework\Features\Documentation\DocumentationSearchIndex;
use Hyde\Hyde;
Expand Down Expand Up @@ -51,4 +52,30 @@ public function testActionGeneratesBuildManifest()
$this->assertNull($manifest['pages'][404]['output_hash']);
$this->assertNull($manifest['pages']['docs/search.json']['source_hash']);
}

public function testExceptionHandlingPrintsDeferredStartMessage()
{
$task = new FailingGenerateBuildManifest();

$this->assertSame(123, $task->run());

$this->assertSame('<comment>Generating build manifest...</comment> ', $task->buffer[0]);
$this->assertSame("<error>Failed</error>\n", $task->buffer[1]);
$this->assertSame('<error>Test exception</error>', $task->buffer[2]);
}
}

class FailingGenerateBuildManifest extends GenerateBuildManifest
{
public array $buffer = [];

public function handle(): void
{
throw new Exception('Test exception', 123);
}

public function write(string $message): void
{
$this->buffer[] = $message;
}
}
Loading