-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve error handling #71
base: 2.0
Are you sure you want to change the base?
Conversation
if (!headers_sent()) { | ||
header('X-Codeception-CodeCoverage-Error: ' . str_replace("\n", ' ', $message), true, 500); | ||
} | ||
setcookie('CODECEPTION_CODECOVERAGE_ERROR', $message); | ||
|
||
echo 'CodeCeption C3 Error: ' . $message; | ||
exit(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block is actually a major change in behaviour.
Before, c3 set a cookie and website continued to work as usual, now it fails loud and clear and the website doesn't work. It isn't a problem for tests, but, if c3.php is included to live website, it would break website for real users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The if-clause here should protect breaking any website when not running tests:
if (!array_key_exists('HTTP_X_CODECEPTION_CODECOVERAGE', $_SERVER)) { | |
return; | |
} |
Also note that any errors encountered could already "break" a website, since a 500 response code is set when no headers are sent yet:
header('X-Codeception-CodeCoverage-Error: ' . str_replace("\n", ' ', $message), true, 500); |
I know this part changes behavior when running tests and is perhaps better suited for a new major version. There's actually two points to this change:
- Echo error message. Possibly makes it easier to debug for first-time users. Showing details could be made optional.
- Stop c3 collection when encountering error. Most calls to __c3_error() look like they should stop execution of c3, but do not. For example, when Codeception is not loaded an error is thrown ( ) but execution continues. This could lead to more errors or unexpected behavior. Another way to solve this is to make those calls throw proper exceptions and catch them to log error and continue normal application execution.
@Naktibalda Would this PR be acceptable for a new major version of c3? |
Improve error handling in a number of ways (see commit messages).
If not all parts of this PR are desirable in general, feel free to cherry pick.
Also fixes #41 and #37