Skip to content

PHPLIB-221: Document GridFS exceptions #296

New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/includes/extracts-error.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,14 @@ content: |
:phpclass:`MongoDB\\Exception\\UnsupportedException` if options are used and
not supported by the selected server (e.g. ``collation``, ``readConcern``,
``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.
...
34 changes: 32 additions & 2 deletions docs/reference/exception-classes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ MongoDB\\Exception\\UnsupportedException
unintended document being deleted.

This class extends the library's :phpclass:`RuntimeException
<MongoDB\\Exception\\RuntimeException>` class and implements the
library's :phpclass:`Exception <MongoDB\\Exception\\Exception>` interface.
<MongoDB\\Exception\\RuntimeException>` class.

.. note::

Expand All @@ -89,6 +88,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
-----------------------------

Expand Down
6 changes: 6 additions & 0 deletions docs/reference/method/MongoDBGridFSBucket-delete.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ Definition

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ Definition

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ Definition

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

Expand Down
5 changes: 5 additions & 0 deletions docs/reference/method/MongoDBGridFSBucket-drop.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ Definition

function drop(): void

Errors/Exceptions
-----------------

.. include:: /includes/extracts/error-driver-runtimeexception.rst

.. todo: add examples
7 changes: 7 additions & 0 deletions docs/reference/method/MongoDBGridFSBucket-find.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ Return Values

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

See Also
Expand Down
7 changes: 7 additions & 0 deletions docs/reference/method/MongoDBGridFSBucket-findOne.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

See Also
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ Return Values
The metadata document associated with the GridFS stream. The return type will
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

See Also
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ Return Values
The ``_id`` field of the metadata document associated with the GridFS stream.
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

See Also
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ Return Values

A readable stream resource.

Errors/Exceptions
-----------------

.. include:: /includes/extracts/error-gridfs-filenotfoundexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst

.. todo: add examples

See Also
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ Return Values

A readable stream resource.

Errors/Exceptions
-----------------

.. include:: /includes/extracts/error-gridfs-filenotfoundexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst

.. todo: add examples

See Also
Expand Down
6 changes: 6 additions & 0 deletions docs/reference/method/MongoDBGridFSBucket-rename.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ Definition

.. 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
Original file line number Diff line number Diff line change
Expand Up @@ -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
by default.

Errors/Exceptions
-----------------

.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst

.. todo: add examples

See Also
Expand Down
5 changes: 5 additions & 0 deletions docs/reference/method/MongoDBGridFSBucket__construct.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ Definition

.. include:: /includes/apiargs/MongoDBGridFSBucket-method-construct-option.rst

Errors/Exceptions
-----------------

.. include:: /includes/extracts/error-invalidargumentexception.rst

Behavior
--------

Expand Down
2 changes: 1 addition & 1 deletion src/Exception/UnsupportedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace MongoDB\Exception;

class UnsupportedException extends RuntimeException implements Exception
class UnsupportedException extends RuntimeException
{
/**
* Thrown when collations are not supported by a server.
Expand Down
41 changes: 30 additions & 11 deletions src/GridFS/Bucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnexpectedValueException;
use MongoDB\GridFS\Exception\CorruptFileException;
use MongoDB\GridFS\Exception\FileNotFoundException;
use MongoDB\Operation\Find;
Expand Down Expand Up @@ -62,7 +64,7 @@ class Bucket
* @param Manager $manager Manager instance from the driver
* @param string $databaseName Database name
* @param array $options Bucket options
* @throws InvalidArgumentException
* @throws InvalidArgumentException for parameter/option parsing errors
*/
public function __construct(Manager $manager, $databaseName, array $options = [])
{
Expand Down Expand Up @@ -137,7 +139,8 @@ public function __debugInfo()
* attempt to delete orphaned chunks.
*
* @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)
{
Expand All @@ -154,8 +157,9 @@ public function delete($id)
*
* @param mixed $id File ID
* @param resource $destination Writable Stream
* @throws FileNotFoundException
* @throws FileNotFoundException if no file could be selected
* @throws InvalidArgumentException if $destination is not a stream
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
public function downloadToStream($id, $destination)
{
Expand Down Expand Up @@ -188,8 +192,9 @@ public function downloadToStream($id, $destination)
* @param string $filename Filename
* @param resource $destination Writable Stream
* @param array $options Download options
* @throws FileNotFoundException
* @throws FileNotFoundException if no file could be selected
* @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 = [])
{
Expand All @@ -203,6 +208,8 @@ public function downloadToStreamByName($filename, $destination, array $options =
/**
* Drops the files and chunks collections associated with this GridFS
* bucket.
*
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
public function drop()
{
Expand All @@ -217,6 +224,9 @@ public function drop()
* @param array|object $filter Query by which to filter documents
* @param array $options Additional options
* @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 = [])
{
Expand All @@ -231,6 +241,9 @@ public function find($filter = [], array $options = [])
* @param array|object $filter Query by which to filter documents
* @param array $options Additional options
* @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 = [])
{
Expand Down Expand Up @@ -262,7 +275,8 @@ public function getDatabaseName()
*
* @param resource $stream GridFS stream
* @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)
{
Expand All @@ -277,8 +291,9 @@ public function getFileDocumentForStream($stream)
*
* @param resource $stream GridFS stream
* @return mixed
* @throws CorruptFileException
* @throws InvalidArgumentException
* @throws CorruptFileException if the file "_id" field does not exist
* @throws InvalidArgumentException if $stream is not a GridFS stream
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
public function getFileIdForStream($stream)
{
Expand All @@ -302,7 +317,8 @@ public function getFileIdForStream($stream)
*
* @param mixed $id File ID
* @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)
{
Expand Down Expand Up @@ -337,7 +353,8 @@ public function openDownloadStream($id)
* @param string $filename Filename
* @param array $options Download options
* @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 = [])
{
Expand Down Expand Up @@ -390,7 +407,8 @@ public function openUploadStream($filename, array $options = [])
*
* @param mixed $id File ID
* @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)
{
Expand Down Expand Up @@ -431,7 +449,8 @@ public function rename($id, $newFilename)
* @param resource $source Readable stream
* @param array $options Stream options
* @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 = [])
{
Expand Down
Loading