Commit 5327ef76 authored by Jeremy Mikola's avatar Jeremy Mikola

PHPLIB-221: Document GridFS exceptions

parent 34ae9870
...@@ -31,4 +31,14 @@ content: | ...@@ -31,4 +31,14 @@ content: |
:phpclass:`MongoDB\\Exception\\UnsupportedException` if options are used and :phpclass:`MongoDB\\Exception\\UnsupportedException` if options are used and
not supported by the selected server (e.g. ``collation``, ``readConcern``, not supported by the selected server (e.g. ``collation``, ``readConcern``,
``writeConcern``). ``writeConcern``).
---
ref: error-gridfs-filenotfoundexception
content: |
:phpclass:`MongoDB\\GridFS\\Exception\\FileNotFoundException` if no file was
found for the selection criteria.
---
ref: error-gridfs-corruptfileexception
content: |
:phpclass:`MongoDB\\GridFS\\Exception\\CorruptFileException` if the file's
metadata or chunk documents contain unexpected or invalid data.
... ...
...@@ -89,6 +89,37 @@ MongoDB\\Exception\\UnsupportedException ...@@ -89,6 +89,37 @@ MongoDB\\Exception\\UnsupportedException
---- ----
MongoDB\\GridFS\\Exception\\CorruptFileException
----------------------------------------
.. phpclass:: MongoDB\\GridFS\\Exception\\CorruptFileException
This exception is thrown if a GridFS file's metadata or chunk documents
contain unexpected or invalid data.
When selecting a GridFS file, this may be thrown if a metadata field has an
incorrect type or its value is out of range (e.g. negative ``length``). When
reading a GridFS file, this may be thrown if a chunk's index is out of
sequence or its binary data's length out of range.
This class extends the library's :phpclass:`RuntimeException
<MongoDB\\Exception\\RuntimeException>` class.
----
MongoDB\\GridFS\\Exception\\FileNotFoundException
----------------------------------------
.. phpclass:: MongoDB\\GridFS\\Exception\\FileNotFoundException
This exception is thrown if no GridFS file was found for the selection
criteria (e.g. ``id``, ``filename``).
This class extends the library's :phpclass:`RuntimeException
<MongoDB\\Exception\\RuntimeException>` class.
----
MongoDB\\Exception\\Exception MongoDB\\Exception\\Exception
----------------------------- -----------------------------
......
...@@ -25,6 +25,12 @@ Definition ...@@ -25,6 +25,12 @@ Definition
.. include:: /includes/apiargs/MongoDBGridFSBucket-method-delete-param.rst .. include:: /includes/apiargs/MongoDBGridFSBucket-method-delete-param.rst
Errors/Exceptions
-----------------
.. include:: /includes/extracts/error-gridfs-filenotfoundexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
Behavior Behavior
-------- --------
......
...@@ -28,6 +28,13 @@ Definition ...@@ -28,6 +28,13 @@ Definition
.. todo: add examples .. todo: add examples
Errors/Exceptions
-----------------
.. include:: /includes/extracts/error-gridfs-filenotfoundexception.rst
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
See Also See Also
-------- --------
......
...@@ -32,6 +32,13 @@ Definition ...@@ -32,6 +32,13 @@ Definition
.. todo: add examples .. todo: add examples
Errors/Exceptions
-----------------
.. include:: /includes/extracts/error-gridfs-filenotfoundexception.rst
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
See Also See Also
-------- --------
......
...@@ -21,4 +21,9 @@ Definition ...@@ -21,4 +21,9 @@ Definition
function drop(): void function drop(): void
Errors/Exceptions
-----------------
.. include:: /includes/extracts/error-driver-runtimeexception.rst
.. todo: add examples .. todo: add examples
...@@ -34,6 +34,13 @@ Return Values ...@@ -34,6 +34,13 @@ Return Values
A :php:`MongoDB\\Driver\\Cursor <class.mongodb-driver-cursor>` object. A :php:`MongoDB\\Driver\\Cursor <class.mongodb-driver-cursor>` object.
Errors/Exceptions
-----------------
.. include:: /includes/extracts/error-unsupportedexception.rst
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
.. todo: add examples .. todo: add examples
See Also See Also
......
...@@ -37,6 +37,13 @@ An array or object for the :term:`first document <natural order>` that matched ...@@ -37,6 +37,13 @@ An array or object for the :term:`first document <natural order>` that matched
the query, or ``null`` if no document matched the query. The return type will the query, or ``null`` if no document matched the query. The return type will
depend on the ``typeMap`` option. depend on the ``typeMap`` option.
Errors/Exceptions
-----------------
.. include:: /includes/extracts/error-unsupportedexception.rst
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
.. todo: add examples .. todo: add examples
See Also See Also
......
...@@ -31,6 +31,12 @@ Return Values ...@@ -31,6 +31,12 @@ Return Values
The metadata document associated with the GridFS stream. The return type will The metadata document associated with the GridFS stream. The return type will
depend on the bucket's ``typeMap`` option. depend on the bucket's ``typeMap`` option.
Errors/Exceptions
-----------------
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
.. todo: add examples .. todo: add examples
See Also See Also
......
...@@ -31,6 +31,13 @@ Return Values ...@@ -31,6 +31,13 @@ Return Values
The ``_id`` field of the metadata document associated with the GridFS stream. The ``_id`` field of the metadata document associated with the GridFS stream.
The return type will depend on the bucket's ``typeMap`` option. The return type will depend on the bucket's ``typeMap`` option.
Errors/Exceptions
-----------------
.. include:: /includes/extracts/error-gridfs-corruptfileexception.rst
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
.. todo: add examples .. todo: add examples
See Also See Also
......
...@@ -30,6 +30,12 @@ Return Values ...@@ -30,6 +30,12 @@ Return Values
A readable stream resource. A readable stream resource.
Errors/Exceptions
-----------------
.. include:: /includes/extracts/error-gridfs-filenotfoundexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
.. todo: add examples .. todo: add examples
See Also See Also
......
...@@ -34,6 +34,12 @@ Return Values ...@@ -34,6 +34,12 @@ Return Values
A readable stream resource. A readable stream resource.
Errors/Exceptions
-----------------
.. include:: /includes/extracts/error-gridfs-filenotfoundexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
.. todo: add examples .. todo: add examples
See Also See Also
......
...@@ -25,4 +25,10 @@ Definition ...@@ -25,4 +25,10 @@ Definition
.. include:: /includes/apiargs/MongoDBGridFSBucket-method-rename-param.rst .. include:: /includes/apiargs/MongoDBGridFSBucket-method-rename-param.rst
Errors/Exceptions
-----------------
.. include:: /includes/extracts/error-gridfs-filenotfoundexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
.. todo: add examples .. todo: add examples
...@@ -37,6 +37,12 @@ GridFS file. If the ``_id`` option is not specified, a new ...@@ -37,6 +37,12 @@ GridFS file. If the ``_id`` option is not specified, a new
:php:`MongoDB\\BSON\\ObjectID <class.mongodb-bson-objectid>` object will be used :php:`MongoDB\\BSON\\ObjectID <class.mongodb-bson-objectid>` object will be used
by default. by default.
Errors/Exceptions
-----------------
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
.. todo: add examples .. todo: add examples
See Also See Also
......
...@@ -29,6 +29,11 @@ Definition ...@@ -29,6 +29,11 @@ Definition
.. include:: /includes/apiargs/MongoDBGridFSBucket-method-construct-option.rst .. include:: /includes/apiargs/MongoDBGridFSBucket-method-construct-option.rst
Errors/Exceptions
-----------------
.. include:: /includes/extracts/error-invalidargumentexception.rst
Behavior Behavior
-------- --------
......
...@@ -7,7 +7,9 @@ use MongoDB\Driver\Manager; ...@@ -7,7 +7,9 @@ use MongoDB\Driver\Manager;
use MongoDB\Driver\ReadConcern; use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnexpectedValueException;
use MongoDB\GridFS\Exception\CorruptFileException; use MongoDB\GridFS\Exception\CorruptFileException;
use MongoDB\GridFS\Exception\FileNotFoundException; use MongoDB\GridFS\Exception\FileNotFoundException;
use MongoDB\Operation\Find; use MongoDB\Operation\Find;
...@@ -62,7 +64,7 @@ class Bucket ...@@ -62,7 +64,7 @@ class Bucket
* @param Manager $manager Manager instance from the driver * @param Manager $manager Manager instance from the driver
* @param string $databaseName Database name * @param string $databaseName Database name
* @param array $options Bucket options * @param array $options Bucket options
* @throws InvalidArgumentException * @throws InvalidArgumentException for parameter/option parsing errors
*/ */
public function __construct(Manager $manager, $databaseName, array $options = []) public function __construct(Manager $manager, $databaseName, array $options = [])
{ {
...@@ -137,7 +139,8 @@ class Bucket ...@@ -137,7 +139,8 @@ class Bucket
* attempt to delete orphaned chunks. * attempt to delete orphaned chunks.
* *
* @param mixed $id File ID * @param mixed $id File ID
* @throws FileNotFoundException * @throws FileNotFoundException if no file could be selected
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/ */
public function delete($id) public function delete($id)
{ {
...@@ -154,8 +157,9 @@ class Bucket ...@@ -154,8 +157,9 @@ class Bucket
* *
* @param mixed $id File ID * @param mixed $id File ID
* @param resource $destination Writable Stream * @param resource $destination Writable Stream
* @throws FileNotFoundException * @throws FileNotFoundException if no file could be selected
* @throws InvalidArgumentException if $destination is not a stream * @throws InvalidArgumentException if $destination is not a stream
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/ */
public function downloadToStream($id, $destination) public function downloadToStream($id, $destination)
{ {
...@@ -188,8 +192,9 @@ class Bucket ...@@ -188,8 +192,9 @@ class Bucket
* @param string $filename Filename * @param string $filename Filename
* @param resource $destination Writable Stream * @param resource $destination Writable Stream
* @param array $options Download options * @param array $options Download options
* @throws FileNotFoundException * @throws FileNotFoundException if no file could be selected
* @throws InvalidArgumentException if $destination is not a stream * @throws InvalidArgumentException if $destination is not a stream
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/ */
public function downloadToStreamByName($filename, $destination, array $options = []) public function downloadToStreamByName($filename, $destination, array $options = [])
{ {
...@@ -203,6 +208,8 @@ class Bucket ...@@ -203,6 +208,8 @@ class Bucket
/** /**
* Drops the files and chunks collections associated with this GridFS * Drops the files and chunks collections associated with this GridFS
* bucket. * bucket.
*
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/ */
public function drop() public function drop()
{ {
...@@ -217,6 +224,9 @@ class Bucket ...@@ -217,6 +224,9 @@ class Bucket
* @param array|object $filter Query by which to filter documents * @param array|object $filter Query by which to filter documents
* @param array $options Additional options * @param array $options Additional options
* @return Cursor * @return Cursor
* @throws UnsupportedException if options are not supported by the selected server
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/ */
public function find($filter = [], array $options = []) public function find($filter = [], array $options = [])
{ {
...@@ -231,6 +241,9 @@ class Bucket ...@@ -231,6 +241,9 @@ class Bucket
* @param array|object $filter Query by which to filter documents * @param array|object $filter Query by which to filter documents
* @param array $options Additional options * @param array $options Additional options
* @return array|object|null * @return array|object|null
* @throws UnsupportedException if options are not supported by the selected server
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/ */
public function findOne($filter = [], array $options = []) public function findOne($filter = [], array $options = [])
{ {
...@@ -262,7 +275,8 @@ class Bucket ...@@ -262,7 +275,8 @@ class Bucket
* *
* @param resource $stream GridFS stream * @param resource $stream GridFS stream
* @return array|object * @return array|object
* @throws InvalidArgumentException * @throws InvalidArgumentException if $stream is not a GridFS stream
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/ */
public function getFileDocumentForStream($stream) public function getFileDocumentForStream($stream)
{ {
...@@ -277,8 +291,9 @@ class Bucket ...@@ -277,8 +291,9 @@ class Bucket
* *
* @param resource $stream GridFS stream * @param resource $stream GridFS stream
* @return mixed * @return mixed
* @throws CorruptFileException * @throws CorruptFileException if the file "_id" field does not exist
* @throws InvalidArgumentException * @throws InvalidArgumentException if $stream is not a GridFS stream
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/ */
public function getFileIdForStream($stream) public function getFileIdForStream($stream)
{ {
...@@ -302,7 +317,8 @@ class Bucket ...@@ -302,7 +317,8 @@ class Bucket
* *
* @param mixed $id File ID * @param mixed $id File ID
* @return resource * @return resource
* @throws FileNotFoundException * @throws FileNotFoundException if no file could be selected
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/ */
public function openDownloadStream($id) public function openDownloadStream($id)
{ {
...@@ -337,7 +353,8 @@ class Bucket ...@@ -337,7 +353,8 @@ class Bucket
* @param string $filename Filename * @param string $filename Filename
* @param array $options Download options * @param array $options Download options
* @return resource * @return resource
* @throws FileNotFoundException * @throws FileNotFoundException if no file could be selected
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/ */
public function openDownloadStreamByName($filename, array $options = []) public function openDownloadStreamByName($filename, array $options = [])
{ {
...@@ -390,7 +407,8 @@ class Bucket ...@@ -390,7 +407,8 @@ class Bucket
* *
* @param mixed $id File ID * @param mixed $id File ID
* @param string $newFilename New filename * @param string $newFilename New filename
* @throws FileNotFoundException * @throws FileNotFoundException if no file could be selected
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/ */
public function rename($id, $newFilename) public function rename($id, $newFilename)
{ {
...@@ -431,7 +449,8 @@ class Bucket ...@@ -431,7 +449,8 @@ class Bucket
* @param resource $source Readable stream * @param resource $source Readable stream
* @param array $options Stream options * @param array $options Stream options
* @return mixed ID of the newly created GridFS file * @return mixed ID of the newly created GridFS file
* @throws InvalidArgumentException if $source is not a stream * @throws InvalidArgumentException if $source is not a GridFS stream
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/ */
public function uploadFromStream($filename, $source, array $options = []) public function uploadFromStream($filename, $source, array $options = [])
{ {
......
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