Commit a36b0799 authored by Jeremy Mikola's avatar Jeremy Mikola

PHPLIB-199: Convert Exceptions to E_USER_WARNING in StreamWrapper

Unfortunately, PHP's StreamWrapper API requires that we trigger errors instead of throwing exceptions. This will affect driver exceptions thrown during IO and CorruptFileException thrown by ReadableStream.
parent 63c2313f
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
namespace MongoDB\GridFS; namespace MongoDB\GridFS;
use Exception;
/** /**
* Stream wrapper for reading and writing a GridFS file. * Stream wrapper for reading and writing a GridFS file.
* *
...@@ -105,7 +107,12 @@ class StreamWrapper ...@@ -105,7 +107,12 @@ class StreamWrapper
return ''; return '';
} }
try {
return $this->stream->downloadNumBytes($count); return $this->stream->downloadNumBytes($count);
} catch (Exception $e) {
trigger_error(sprintf('%s: %s', get_class($e), $e->getMessage()), \E_USER_WARNING);
return false;
}
} }
/** /**
...@@ -137,8 +144,12 @@ class StreamWrapper ...@@ -137,8 +144,12 @@ class StreamWrapper
return 0; return 0;
} }
$this->stream->insertChunks($data); try {
return strlen($data); return $this->stream->insertChunks($data);
} catch (Exception $e) {
trigger_error(sprintf('%s: %s', get_class($e), $e->getMessage()), \E_USER_WARNING);
return false;
}
} }
/** /**
......
...@@ -125,7 +125,7 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -125,7 +125,7 @@ class BucketFunctionalTest extends FunctionalTestCase
} }
/** /**
* @expectedException MongoDB\GridFS\Exception\CorruptFileException * @expectedException PHPUnit_Framework_Error_Warning
*/ */
public function testDownloadingFileWithMissingChunk() public function testDownloadingFileWithMissingChunk()
{ {
...@@ -137,7 +137,7 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -137,7 +137,7 @@ class BucketFunctionalTest extends FunctionalTestCase
} }
/** /**
* @expectedException MongoDB\GridFS\Exception\CorruptFileException * @expectedException PHPUnit_Framework_Error_Warning
*/ */
public function testDownloadingFileWithUnexpectedChunkIndex() public function testDownloadingFileWithUnexpectedChunkIndex()
{ {
...@@ -152,7 +152,7 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -152,7 +152,7 @@ class BucketFunctionalTest extends FunctionalTestCase
} }
/** /**
* @expectedException MongoDB\GridFS\Exception\CorruptFileException * @expectedException PHPUnit_Framework_Error_Warning
*/ */
public function testDownloadingFileWithUnexpectedChunkSize() public function testDownloadingFileWithUnexpectedChunkSize()
{ {
......
...@@ -6,9 +6,9 @@ use MongoDB\Collection; ...@@ -6,9 +6,9 @@ use MongoDB\Collection;
use MongoDB\BSON\Binary; use MongoDB\BSON\Binary;
use MongoDB\BSON\ObjectId; use MongoDB\BSON\ObjectId;
use MongoDB\BSON\UTCDateTime; use MongoDB\BSON\UTCDateTime;
use MongoDB\Exception\RuntimeException;
use MongoDB\Operation\BulkWrite; use MongoDB\Operation\BulkWrite;
use DateTime; use DateTime;
use Exception;
use IteratorIterator; use IteratorIterator;
use LogicException; use LogicException;
use MultipleIterator; use MultipleIterator;
...@@ -50,7 +50,7 @@ class SpecFunctionalTest extends FunctionalTestCase ...@@ -50,7 +50,7 @@ class SpecFunctionalTest extends FunctionalTestCase
try { try {
$result = $this->executeAct($test['act']); $result = $this->executeAct($test['act']);
} catch (RuntimeException $e) { } catch (Exception $e) {
$result = $e; $result = $e;
} }
...@@ -333,7 +333,10 @@ class SpecFunctionalTest extends FunctionalTestCase ...@@ -333,7 +333,10 @@ class SpecFunctionalTest extends FunctionalTestCase
case 'ChunkIsMissing': case 'ChunkIsMissing':
case 'ChunkIsWrongSize': case 'ChunkIsWrongSize':
return 'MongoDB\GridFS\Exception\CorruptFileException'; /* Although ReadableStream throws a CorruptFileException, the
* stream wrapper will convert it to a PHP error of type
* E_USER_WARNING. */
return 'PHPUnit_Framework_Error_Warning';
default: default:
throw new LogicException('Unsupported error: ' . $error); throw new LogicException('Unsupported error: ' . $error);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment