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 |
112 msg = 'No entity with eid %s in %s' |
112 msg = 'No entity with eid %s in %s' |
113 |
113 |
114 |
114 |
115 # registry exceptions ######################################################### |
115 # registry exceptions ######################################################### |
116 |
116 |
117 class RegistryException(CubicWebException): |
117 # pre 3.15 bw compat |
118 """raised when an unregistered view is called""" |
118 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 |
119 |
144 class UnknownProperty(RegistryException): |
120 class UnknownProperty(RegistryException): |
145 """property found in database but unknown in registry""" |
121 """property found in database but unknown in registry""" |
146 |
122 |
147 # query exception ############################################################# |
123 # query exception ############################################################# |
152 class NotAnEntity(CubicWebRuntimeError): |
128 class NotAnEntity(CubicWebRuntimeError): |
153 """raised when get_entity is called for a column which doesn't contain |
129 """raised when get_entity is called for a column which doesn't contain |
154 a non final entity |
130 a non final entity |
155 """ |
131 """ |
156 |
132 |
|
133 class UndoTransactionException(QueryError): |
|
134 """Raised when undoing a transaction could not be performed completely. |
|
135 |
|
136 Note that : |
|
137 1) the partial undo operation might be acceptable |
|
138 depending upon the final application |
|
139 |
|
140 2) the undo operation can also fail with a `ValidationError` in |
|
141 cases where the undoing breaks integrity constraints checked |
|
142 immediately. |
|
143 |
|
144 3) It might be that neither of those exception is raised but a |
|
145 subsequent `commit` might raise a `ValidationError` in cases |
|
146 where the undoing breaks integrity constraints checked at |
|
147 commit time. |
|
148 |
|
149 :type txuuix: int |
|
150 :param txuuid: Unique identifier of the partialy undone transaction |
|
151 |
|
152 :type errors: list |
|
153 :param errors: List of errors occured during undoing |
|
154 """ |
|
155 msg = u"The following error(s) occured while undoing transaction #%d : %s" |
|
156 |
|
157 def __init__(self, txuuid, errors): |
|
158 super(UndoTransactionException, self).__init__(txuuid, errors) |
|
159 self.txuuid = txuuid |
|
160 self.errors = errors |
|
161 |
157 # tools exceptions ############################################################ |
162 # tools exceptions ############################################################ |
158 |
163 |
159 class ExecutionError(Exception): |
164 class ExecutionError(Exception): |
160 """server execution control error (already started, not running...)""" |
165 """server execution control error (already started, not running...)""" |
161 |
166 |
162 # pylint: disable=W0611 |
167 # pylint: disable=W0611 |
163 from logilab.common.clcommands import BadCommandUsage |
168 from logilab.common.clcommands import BadCommandUsage |
|
169 |