_exceptions.py
brancholdstable
changeset 8746 88c71ad83d47
parent 8602 d066ba3bb07d
child 8609 112a04c0473d
equal deleted inserted replaced
8507:0c111b232927 8746:88c71ad83d47
     1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     3 #
     4 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     5 #
     5 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    14 # details.
    14 # details.
    15 #
    15 #
    16 # You should have received a copy of the GNU Lesser General Public License along
    16 # You should have received a copy of the GNU Lesser General Public License along
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """Exceptions shared by different cubicweb packages.
    18 """Exceptions shared by different cubicweb packages."""
    19 
    19 
    20 
       
    21 """
       
    22 __docformat__ = "restructuredtext en"
    20 __docformat__ = "restructuredtext en"
    23 
    21 
    24 from yams import ValidationError
    22 from yams import ValidationError
    25 
    23 
    26 # abstract exceptions #########################################################
    24 # abstract exceptions #########################################################
    30     msg = ""
    28     msg = ""
    31     def __str__(self):
    29     def __str__(self):
    32         if self.msg:
    30         if self.msg:
    33             if self.args:
    31             if self.args:
    34                 return self.msg % tuple(self.args)
    32                 return self.msg % tuple(self.args)
    35             return self.msg
    33             else:
    36         return ' '.join(unicode(arg) for arg in self.args)
    34                 return self.msg
    37 
    35         else:
       
    36             return u' '.join(unicode(arg) for arg in self.args)
    38 
    37 
    39 class ConfigurationError(CubicWebException):
    38 class ConfigurationError(CubicWebException):
    40     """a misconfiguration error"""
    39     """a misconfiguration error"""
    41 
    40 
    42 class InternalError(CubicWebException):
    41 class InternalError(CubicWebException):
    81     """usually due to bad multisources configuration or rql query"""
    80     """usually due to bad multisources configuration or rql query"""
    82 
    81 
    83 class UniqueTogetherError(RepositoryError):
    82 class UniqueTogetherError(RepositoryError):
    84     """raised when a unique_together constraint caused an IntegrityError"""
    83     """raised when a unique_together constraint caused an IntegrityError"""
    85 
    84 
       
    85 
    86 # security exceptions #########################################################
    86 # security exceptions #########################################################
    87 
    87 
    88 class Unauthorized(SecurityError):
    88 class Unauthorized(SecurityError):
    89     """raised when a user tries to perform an action without sufficient
    89     """raised when a user tries to perform an action without sufficient
    90     credentials
    90     credentials
   101                 return ' '.join(self.args)
   101                 return ' '.join(self.args)
   102             return self.msg
   102             return self.msg
   103         except Exception, ex:
   103         except Exception, ex:
   104             return str(ex)
   104             return str(ex)
   105 
   105 
       
   106 class Forbidden(SecurityError):
       
   107     """raised when a user tries to perform a forbidden action
       
   108     """
       
   109 
   106 # source exceptions ###########################################################
   110 # source exceptions ###########################################################
   107 
   111 
   108 class EidNotInSource(SourceException):
   112 class EidNotInSource(SourceException):
   109     """trying to access an object with a particular eid from a particular
   113     """trying to access an object with a particular eid from a particular
   110     source has failed
   114     source has failed
   112     msg = 'No entity with eid %s in %s'
   116     msg = 'No entity with eid %s in %s'
   113 
   117 
   114 
   118 
   115 # registry exceptions #########################################################
   119 # registry exceptions #########################################################
   116 
   120 
   117 class RegistryException(CubicWebException):
   121 # pre 3.15 bw compat
   118     """raised when an unregistered view is called"""
   122 from logilab.common.registry import RegistryException, ObjectNotFound, NoSelectableObject
   119 
       
   120 class RegistryNotFound(RegistryException):
       
   121     """raised when an unknown registry is requested
       
   122 
       
   123     this is usually a programming/typo error...
       
   124     """
       
   125 
       
   126 class ObjectNotFound(RegistryException):
       
   127     """raised when an unregistered object is requested
       
   128 
       
   129     this may be a programming/typo or a misconfiguration error
       
   130     """
       
   131 
       
   132 class NoSelectableObject(RegistryException):
       
   133     """raised when no appobject is selectable for a given context."""
       
   134     def __init__(self, args, kwargs, appobjects):
       
   135         self.args = args
       
   136         self.kwargs = kwargs
       
   137         self.appobjects = appobjects
       
   138 
       
   139     def __str__(self):
       
   140         return ('args: %s, kwargs: %s\ncandidates: %s'
       
   141                 % (self.args, self.kwargs.keys(), self.appobjects))
       
   142 
       
   143 
   123 
   144 class UnknownProperty(RegistryException):
   124 class UnknownProperty(RegistryException):
   145     """property found in database but unknown in registry"""
   125     """property found in database but unknown in registry"""
   146 
   126 
   147 # query exception #############################################################
   127 # query exception #############################################################
   152 class NotAnEntity(CubicWebRuntimeError):
   132 class NotAnEntity(CubicWebRuntimeError):
   153     """raised when get_entity is called for a column which doesn't contain
   133     """raised when get_entity is called for a column which doesn't contain
   154     a non final entity
   134     a non final entity
   155     """
   135     """
   156 
   136 
       
   137 class UndoTransactionException(QueryError):
       
   138     """Raised when undoing a transaction could not be performed completely.
       
   139 
       
   140     Note that :
       
   141       1) the partial undo operation might be acceptable
       
   142          depending upon the final application
       
   143 
       
   144       2) the undo operation can also fail with a `ValidationError` in
       
   145          cases where the undoing breaks integrity constraints checked
       
   146          immediately.
       
   147 
       
   148       3) It might be that neither of those exception is raised but a
       
   149          subsequent `commit` might raise a `ValidationError` in cases
       
   150          where the undoing breaks integrity constraints checked at
       
   151          commit time.
       
   152 
       
   153     :type txuuix: int
       
   154     :param txuuid: Unique identifier of the partialy undone transaction
       
   155 
       
   156     :type errors: list
       
   157     :param errors: List of errors occured during undoing
       
   158     """
       
   159     msg = u"The following error(s) occured while undoing transaction #%d : %s"
       
   160 
       
   161     def __init__(self, txuuid, errors):
       
   162         super(UndoTransactionException, self).__init__(txuuid, errors)
       
   163         self.txuuid = txuuid
       
   164         self.errors = errors
       
   165 
   157 # tools exceptions ############################################################
   166 # tools exceptions ############################################################
   158 
   167 
   159 class ExecutionError(Exception):
   168 class ExecutionError(Exception):
   160     """server execution control error (already started, not running...)"""
   169     """server execution control error (already started, not running...)"""
   161 
   170 
   162 # pylint: disable=W0611
   171 # pylint: disable=W0611
   163 from logilab.common.clcommands import BadCommandUsage
   172 from logilab.common.clcommands import BadCommandUsage
       
   173