From 3fea99f6f2c48311c515c2c2c9430d8d2f7a22da Mon Sep 17 00:00:00 2001 From: gravel Date: Fri, 19 May 2023 15:33:10 +0000 Subject: [PATCH] Propagate failure in HTML generation --- php/generate-html.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/php/generate-html.php b/php/generate-html.php index 638a48b..9034ccc 100644 --- a/php/generate-html.php +++ b/php/generate-html.php @@ -30,15 +30,22 @@ $relpath = str_replace($TEMPLATES_ROOT, "", $phppath); $docpath = str_replace(".php", ".html", $docpath); - // This works? Yes, yes it does. // We do this to isolate the environment and include-once triggers, // otherwise we could include the documents in an ob_* wrapper. - // Same as shell_exec, except we don't have to escape quotes. log_info("Generating output for $relpath."); - $document = `cd "$TEMPLATES_ROOT"; php $phppath $flags`; + $output = []; - file_put_contents($docpath, $document); + $exit_code = 0; + + exec("cd '$TEMPLATES_ROOT'; php '$phppath' $flags", $output, $exit_code); + + if ($exit_code != 0 || empty($output)) { + log_error("HTML generation failed."); + exit(255); + } + + file_put_contents($docpath, join("\n", $output)); } log_info("Done generating HTML.");