Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Error handling in AbstractWriter::write using Zend\Stdlib\ErrorHandler #2370

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants
@ghost

ghost commented Sep 16, 2012

Generalizes the use of Zend\Stdlib\ErrorHandler in all concrete writers
while at the same allowing to turn off that feature by calling
setConvertWriteErrorsToExceptions on any instance (which makes it safe
to use any Writer inside a custom error handler).

This is a follow up of a previous pull request zendframework#2330 and makes it possible to avoid running into the issue reported on JIRA http://framework.zend.com/issues/browse/ZF2-541

Error handling in AbstractWriter::write using Zend\Stdlib\ErrorHandler
Generalizes the use of Zend\Stdlib\ErrorHandler in all concrete writers
while at the same allowing to turn off that feature by calling
setConvertWriteErrorsToExceptions on any instance (which makes it safe
to use any Writer inside a custom error handler).

@b-durand b-durand commented on the diff Sep 17, 2012

library/Zend/Log/Writer/AbstractWriter.php
@@ -134,8 +149,32 @@ public function write(array $event)
}
}
- // exception occurs on error
- $this->doWrite($event);
+ $errorHandlerStarted = false;
+
+ if ($this->convertWriteErrorsToExceptions && !ErrorHandler::started()) {
+ ErrorHandler::start($this->errorsToExceptionsConversionLevel);
+ $errorHandlerStarted = true;
+ }
+
+ try {
+ $this->doWrite($event);
+ }
+ catch (\Exception $e)
@b-durand

b-durand Sep 17, 2012

Contributor

Have you seen the Travis build indicates that your commit has an error? The error can be related to a test or coding standards.

Here, it's an CS issue :

tests/ZendTest/Log/Writer/AbstractTest.php (trailing_spaces)
library/Zend/Log/Writer/AbstractWriter.php (trailing_spaces, braces)

} catch (Exception $e) {

You should add import (e.g. use) for the Exception class, and configure your editor to remove trailing spaces auto.

EDIT: ErrorHandler raise an ErrorException instead of Exception, if we have an exception, the cause is not linked to fail on write in a file.

@ghost

ghost Sep 18, 2012

OK thanks for the info - I use Zend Studio 9, Is the formatter shipped with Studio 9 completely up-to-date o?

weierophinney added a commit that referenced this pull request Sep 18, 2012

[#2370] CS fixes
- Trailing whitespace
- Braces

weierophinney added a commit that referenced this pull request Sep 18, 2012

Owner

weierophinney commented Sep 18, 2012

@lowcoders I have no clue if the formatter in Studio follows PSR-2 at this point; I'll drop that team an email to recommend it.

I've fixed the CS errors, and merged to master and develop.

@ghost ghost assigned weierophinney Sep 18, 2012

@ghost

ghost commented Sep 19, 2012

Thanks!

weierophinney added a commit to zendframework/zend-log that referenced this pull request May 15, 2015

[zendframework/zendframework#2370] CS fixes
- Trailing whitespace
- Braces

weierophinney added a commit to zendframework/zend-log that referenced this pull request May 15, 2015

weierophinney added a commit to zendframework/zend-log that referenced this pull request May 15, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment