From f7811b927e9850cb0b922a325ee9b8d95377b54d Mon Sep 17 00:00:00 2001 From: Marco van 't Wout Date: Wed, 19 May 2021 11:12:21 +0200 Subject: [PATCH 1/3] Fix notice when handling c3 error before C3_CODECOVERAGE_MEDIATE_STORAGE is defined --- c3.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/c3.php b/c3.php index 3c59a62..3116d44 100644 --- a/c3.php +++ b/c3.php @@ -38,9 +38,13 @@ if (!function_exists('__c3_error')) { function __c3_error($message) { - $errorLogFile = defined('C3_CODECOVERAGE_ERROR_LOG_FILE') ? - C3_CODECOVERAGE_ERROR_LOG_FILE : - C3_CODECOVERAGE_MEDIATE_STORAGE . DIRECTORY_SEPARATOR . 'error.txt'; + if (defined('C3_CODECOVERAGE_ERROR_LOG_FILE')) { + $errorLogFile = C3_CODECOVERAGE_ERROR_LOG_FILE; + } elseif (defined('C3_CODECOVERAGE_MEDIATE_STORAGE')) { + $errorLogFile = C3_CODECOVERAGE_MEDIATE_STORAGE . DIRECTORY_SEPARATOR . 'error.txt'; + } else { + $errorLogFile = null; + } if (is_writable($errorLogFile)) { file_put_contents($errorLogFile, $message); } else { From ca3b3de5cc4a169a1585a46c4ba6834c4d88852b Mon Sep 17 00:00:00 2001 From: Marco van 't Wout Date: Wed, 19 May 2021 11:26:40 +0200 Subject: [PATCH 2/3] Attempt to write error log file even if it doesn't exist yet --- c3.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/c3.php b/c3.php index 3116d44..1deb124 100644 --- a/c3.php +++ b/c3.php @@ -45,11 +45,13 @@ function __c3_error($message) } else { $errorLogFile = null; } - if (is_writable($errorLogFile)) { - file_put_contents($errorLogFile, $message); - } else { - $message = "Could not write error to log file ($errorLogFile), original message: $message"; + + if (isset($errorLogFile)) { + if (@file_put_contents($errorLogFile, $message) === false) { + $message = "Could not write error to log file ($errorLogFile), original message: $message"; + } } + if (!headers_sent()) { header('X-Codeception-CodeCoverage-Error: ' . str_replace("\n", ' ', $message), true, 500); } From 02e0cb743228af77bea2bd6a809a57b5cd9be8f7 Mon Sep 17 00:00:00 2001 From: Marco van 't Wout Date: Wed, 19 May 2021 11:34:18 +0200 Subject: [PATCH 3/3] Echo c3 error to screen and stop execution. --- c3.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/c3.php b/c3.php index 1deb124..0ff4359 100644 --- a/c3.php +++ b/c3.php @@ -56,6 +56,9 @@ function __c3_error($message) header('X-Codeception-CodeCoverage-Error: ' . str_replace("\n", ' ', $message), true, 500); } setcookie('CODECEPTION_CODECOVERAGE_ERROR', $message); + + echo 'CodeCeption C3 Error: ' . $message; + exit(1); } }