Use PyMongoError instead of BaseMongoDBException
Note that this is changing the exception hierarchy somewhat as well, as I would rather not muck things up with multiple inheritance. This is a breaking change if you depend on ConnectionFailure being an IOError or InvalidBSON being a ValueError, for example. If this creates issues for anybody please let us know and we can figure out a better workaround. Also add Michael to contributors list.
This commit is contained in:
parent
8e50ffb272
commit
c8e64f4c02
@ -16,3 +16,4 @@ The following is a list of people who have contributed to
|
||||
- Andrey Fedorov (andreyf)
|
||||
- Joshua Roesslein (joshthecoder)
|
||||
- Gregg Lind (gregglind)
|
||||
- Michael Schurter (schmichael)
|
||||
|
||||
@ -14,10 +14,13 @@
|
||||
|
||||
"""Exceptions raised by the Mongo driver."""
|
||||
|
||||
class BaseMongoDBException(Exception):
|
||||
"""Common base class for all MongoDB exceptions"""
|
||||
class PyMongoError(Exception):
|
||||
"""Base class for all PyMongo exceptions.
|
||||
|
||||
class ConnectionFailure(BaseMongoDBException, IOError):
|
||||
.. versionadded:: 1.3+
|
||||
"""
|
||||
|
||||
class ConnectionFailure(PyMongoError):
|
||||
"""Raised when a connection to the database cannot be made or is lost.
|
||||
"""
|
||||
|
||||
@ -34,12 +37,12 @@ class AutoReconnect(ConnectionFailure):
|
||||
"""
|
||||
|
||||
|
||||
class ConfigurationError(BaseMongoDBException):
|
||||
class ConfigurationError(PyMongoError):
|
||||
"""Raised when something is incorrectly configured.
|
||||
"""
|
||||
|
||||
|
||||
class OperationFailure(BaseMongoDBException):
|
||||
class OperationFailure(PyMongoError):
|
||||
"""Raised when a database operation fails.
|
||||
"""
|
||||
|
||||
@ -51,36 +54,36 @@ class DuplicateKeyError(OperationFailure):
|
||||
"""
|
||||
|
||||
|
||||
class InvalidOperation(BaseMongoDBException):
|
||||
class InvalidOperation(PyMongoError):
|
||||
"""Raised when a client attempts to perform an invalid operation.
|
||||
"""
|
||||
|
||||
|
||||
class CollectionInvalid(BaseMongoDBException):
|
||||
class CollectionInvalid(PyMongoError):
|
||||
"""Raised when collection validation fails.
|
||||
"""
|
||||
|
||||
|
||||
class InvalidName(BaseMongoDBException, ValueError):
|
||||
class InvalidName(PyMongoError):
|
||||
"""Raised when an invalid name is used.
|
||||
"""
|
||||
|
||||
|
||||
class InvalidBSON(BaseMongoDBException, ValueError):
|
||||
class InvalidBSON(PyMongoError):
|
||||
"""Raised when trying to create a BSON object from invalid data.
|
||||
"""
|
||||
|
||||
|
||||
class InvalidStringData(BaseMongoDBException, ValueError):
|
||||
class InvalidStringData(PyMongoError):
|
||||
"""Raised when trying to encode a string containing non-UTF8 data.
|
||||
"""
|
||||
|
||||
|
||||
class InvalidDocument(BaseMongoDBException, ValueError):
|
||||
class InvalidDocument(PyMongoError):
|
||||
"""Raised when trying to create a BSON object from an invalid document.
|
||||
"""
|
||||
|
||||
|
||||
class InvalidId(BaseMongoDBException, ValueError):
|
||||
class InvalidId(PyMongoError):
|
||||
"""Raised when trying to create an ObjectId from invalid data.
|
||||
"""
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
"""Test the collection module."""
|
||||
|
||||
import warnings
|
||||
import unittest
|
||||
import re
|
||||
|
||||
@ -1,16 +1,32 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2009 10gen, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""Test the errors module."""
|
||||
|
||||
import unittest
|
||||
import sys
|
||||
sys.path[0:0] = [""]
|
||||
|
||||
import pymongo
|
||||
from pymongo.errors import BaseMongoDBException
|
||||
from pymongo import Connection
|
||||
from pymongo.errors import PyMongoError
|
||||
|
||||
|
||||
class TestErrors(unittest.TestCase):
|
||||
|
||||
def test_base_exception(self):
|
||||
self.assertRaises(BaseMongoDBException, pymongo.Connection, port=0)
|
||||
self.assertRaises(PyMongoError, Connection, port=0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user