From 3e2362780cf7d29a497edb10b3ab37c582f036fa Mon Sep 17 00:00:00 2001 From: Christoph Lehmann Date: Mon, 10 Jun 2024 15:39:11 +0200 Subject: [PATCH] Streamline exit(1) to web response with HTTP status code 500 With this critical error messages like the following now sends the HTTP status code 500 instead 200 in order to state something is not okay on the server side. Flow could not create the directory "/var/www/html/Data/Persistent". Please check the file permissions manually or run "sudo ./flow flow:core:setfilepermissions" to fix the problem. (Error #1347526553) Resolves: #3364 --- Neos.Flow/Classes/Core/Bootstrap.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Neos.Flow/Classes/Core/Bootstrap.php b/Neos.Flow/Classes/Core/Bootstrap.php index 267233ca2e..8d77caaf61 100644 --- a/Neos.Flow/Classes/Core/Bootstrap.php +++ b/Neos.Flow/Classes/Core/Bootstrap.php @@ -497,6 +497,7 @@ protected function defineConstants() $expectedPath = Files::getUnixStylePath(realpath(FLOW_PATH_FLOW)) . '/'; if ($testPath !== $expectedPath) { echo('Flow: Invalid root path. (Error #1248964375)' . PHP_EOL . '"' . $testPath . '" does not lead to' . PHP_EOL . '"' . $expectedPath . '"' . PHP_EOL); + http_response_code(500); exit(1); } define('FLOW_PATH_ROOT', $rootPath); @@ -547,15 +548,18 @@ protected function ensureRequiredEnvironment() { if (DIRECTORY_SEPARATOR !== '/' && PHP_WINDOWS_VERSION_MAJOR < 6) { echo('Flow does not support Windows versions older than Windows Vista or Windows Server 2008 (Error #1312463704)' . PHP_EOL); + http_response_code(500); exit(1); } if (!extension_loaded('Reflection')) { echo('The PHP extension "Reflection" is required by Flow.' . PHP_EOL); + http_response_code(500); exit(1); } $method = new \ReflectionMethod(__CLASS__, __FUNCTION__); if ($method->getDocComment() === false || $method->getDocComment() === '') { echo('Reflection of doc comments is not supported by your PHP setup. Please check if you have installed an accelerator which removes doc comments.' . PHP_EOL); + http_response_code(500); exit(1); } @@ -568,12 +572,14 @@ protected function ensureRequiredEnvironment() if (!is_dir(FLOW_PATH_DATA) && !is_link(FLOW_PATH_DATA)) { if (!@mkdir(FLOW_PATH_DATA)) { echo('Flow could not create the directory "' . FLOW_PATH_DATA . '". Please check the file permissions manually or run "sudo ./flow flow:core:setfilepermissions" to fix the problem. (Error #1347526552)'); + http_response_code(500); exit(1); } } if (!is_dir(FLOW_PATH_DATA . 'Persistent') && !is_link(FLOW_PATH_DATA . 'Persistent')) { if (!@mkdir(FLOW_PATH_DATA . 'Persistent')) { echo('Flow could not create the directory "' . FLOW_PATH_DATA . 'Persistent". Please check the file permissions manually or run "sudo ./flow flow:core:setfilepermissions" to fix the problem. (Error #1347526553)'); + http_response_code(500); exit(1); } } @@ -582,6 +588,7 @@ protected function ensureRequiredEnvironment() $oldMask = umask(000); if (!@mkdir(FLOW_PATH_TEMPORARY, 0777, true)) { echo('Flow could not create the directory "' . FLOW_PATH_TEMPORARY . '". Please check the file permissions manually or run "sudo ./flow flow:core:setfilepermissions" to fix the problem. (Error #1441354578)'); + http_response_code(500); exit(1); } umask($oldMask);