diff --git a/src/Framework/Actions/PostBuildTasks/GenerateBuildManifest.php b/src/Framework/Actions/PostBuildTasks/GenerateBuildManifest.php index 2a5a2c12..f0435479 100644 --- a/src/Framework/Actions/PostBuildTasks/GenerateBuildManifest.php +++ b/src/Framework/Actions/PostBuildTasks/GenerateBuildManifest.php @@ -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; @@ -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("{$this->getMessage()}... "); + parent::handleExceptionReporting($exception); } } diff --git a/src/Framework/Features/BuildTasks/BuildTask.php b/src/Framework/Features/BuildTasks/BuildTask.php index ac226bdd..689a5200 100644 --- a/src/Framework/Features/BuildTasks/BuildTask.php +++ b/src/Framework/Features/BuildTasks/BuildTask.php @@ -49,13 +49,7 @@ public function run(?OutputStyle $output = null): int $this->handle(); $this->printFinishMessage(); } catch (Throwable $exception) { - if ($exception instanceof BuildTaskSkippedException) { - $this->write("Skipped\n"); - $this->write(" > {$exception->getMessage()}"); - } else { - $this->write("Failed\n"); - $this->write("{$exception->getMessage()}"); - } + $this->handleExceptionReporting($exception); $this->exitCode = $exception->getCode(); } @@ -123,4 +117,15 @@ public function withExecutionTime(): static return $this; } + + protected function handleExceptionReporting(Throwable $exception): void + { + if ($exception instanceof BuildTaskSkippedException) { + $this->write("Skipped\n"); + $this->write(" > {$exception->getMessage()}"); + } else { + $this->write("Failed\n"); + $this->write("{$exception->getMessage()}"); + } + } } diff --git a/tests/Unit/GenerateBuildManifestTest.php b/tests/Unit/GenerateBuildManifestTest.php index bc8510e7..d8410dcc 100644 --- a/tests/Unit/GenerateBuildManifestTest.php +++ b/tests/Unit/GenerateBuildManifestTest.php @@ -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; @@ -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('Generating build manifest... ', $task->buffer[0]); + $this->assertSame("Failed\n", $task->buffer[1]); + $this->assertSame('Test exception', $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; + } }