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

Closed
wants to merge 1 commit into
from

Projects

None yet

4 participants

@lowcoders
Contributor

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 #2330 and makes it possible to avoid running into the issue reported on JIRA http://framework.zend.com/issues/browse/ZF2-541

@franckstauffer franckstauffer 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).
c277fa4
@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.

@lowcoders
lowcoders Sep 18, 2012 Contributor

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

@weierophinney weierophinney added a commit that referenced this pull request Sep 18, 2012
@weierophinney weierophinney [#2370] CS fixes
- Trailing whitespace
- Braces
1a57370
@weierophinney weierophinney added a commit that closed this pull request Sep 18, 2012
@weierophinney weierophinney Merge branch 'hotfix/zf2-541'
Close #2370
0e3d6e8
@weierophinney
Member

@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.

@lowcoders
Contributor

Thanks!

@weierophinney weierophinney added a commit to zendframework/zend-log that referenced this pull request May 15, 2015
@weierophinney weierophinney [zendframework/zendframework#2370] CS fixes
- Trailing whitespace
- Braces
ef1c82b
@weierophinney weierophinney added a commit to zendframework/zend-log that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge branch 'hotfix/zf2-541' 8af24aa
@weierophinney weierophinney added a commit to zendframework/zend-log that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge branch 'hotfix/zf2-541' into develop 0f107cb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment