-
Notifications
You must be signed in to change notification settings - Fork 152
SapiEmitter::emitBody() suppresses exceptions by using StreamInterface::__toString() #181
Comments
It just occurred to me - why is $stream = $response->getBody();
if ($stream->isSeekable()) {
$stream->rewind();
}
while (!$stream->eof()) {
echo $stream->read(1048576);
} |
I performed a ton of benchmarks when developing psr-7 that indicated that
|
Doesn't everybody "need" their exceptions not to be ignored? Isn't that why they throw exceptions? |
Moreover, toString always returns an empty string when isSeekable is false due to the unchecked call to rewind there. I don't think toString should be used in SapiEmitter either. |
This repository has been closed and moved to laminas/laminas-diactoros; a new issue has been opened at laminas/laminas-diactoros#20. |
SapiEmitter::emitBody()
is currently:The definition of
StreamInterface::__toString()
specifies:and
Zend\Diactoros\Stream::__toString()
indeed suppresses run-time exceptions:GuzzleHttp\Psr7\Stream::__toString()
even suppresses all exceptions:As a practical result of this, whenever there is an exception in the process of reading the stream, instead of it bubbling up to the next matching
catch
block or to the exception handler to notify the developer, the HTTP client gets an empty response instead. In other words, an error which the developer could have been notified of directly via their error reporting system is instead translated into something the user must report manually. I don't want to wait for our users to submit bugs when they see a white page. I want errors going to our error reporting system wherever possible (currently Bugsnag) so we know about it immediately.I don't know what "conform with PHP's string casting operations means", but I did find this:
So it seems to me,
__toString()
in PHP is basically broken when it comes to exceptions. Either you allow it to throw exceptions, in which case they don't bubble and you get a fatal error instead, or you suppress the exceptions and turn them into a broken result which the user has to report. Neither are ideal.I therefore propose that
SapiEmitter::emitBody()
not depend on__toString()
and instead be:Do you think this would be a good idea?
The text was updated successfully, but these errors were encountered: