author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
Fri, 29 Mar 2013 12:47:04 +0100 | |
changeset 8840 | bd5b5759c9b3 |
parent 8695 | 358d8bed9626 |
child 9175 | a7412e884d7b |
permissions | -rw-r--r-- |
8556
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8265
diff
changeset
|
1 |
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6491
diff
changeset
|
18 |
"""Exceptions shared by different cubicweb packages.""" |
0 | 19 |
|
20 |
__docformat__ = "restructuredtext en" |
|
21 |
||
8556
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8265
diff
changeset
|
22 |
from yams import ValidationError as ValidationError |
0 | 23 |
|
24 |
# abstract exceptions ######################################################### |
|
25 |
||
26 |
class CubicWebException(Exception): |
|
27 |
"""base class for cubicweb server exception""" |
|
28 |
msg = "" |
|
29 |
def __str__(self): |
|
30 |
if self.msg: |
|
31 |
if self.args: |
|
32 |
return self.msg % tuple(self.args) |
|
8265
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
33 |
else: |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
34 |
return self.msg |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
35 |
else: |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
36 |
return u' '.join(unicode(arg) for arg in self.args) |
0 | 37 |
|
38 |
class ConfigurationError(CubicWebException): |
|
39 |
"""a misconfiguration error""" |
|
40 |
||
41 |
class InternalError(CubicWebException): |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
42 |
"""base class for exceptions which should not occurs""" |
0 | 43 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
44 |
class SecurityError(CubicWebException): |
0 | 45 |
"""base class for cubicweb server security exception""" |
46 |
||
47 |
class RepositoryError(CubicWebException): |
|
48 |
"""base class for repository exceptions""" |
|
49 |
||
50 |
class SourceException(CubicWebException): |
|
51 |
"""base class for source exceptions""" |
|
52 |
||
53 |
class CubicWebRuntimeError(CubicWebException): |
|
54 |
"""base class for runtime exceptions""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
55 |
|
0 | 56 |
# repository exceptions ####################################################### |
57 |
||
58 |
class ConnectionError(RepositoryError): |
|
59 |
"""raised when a bad connection id is given or when an attempt to establish |
|
5032 | 60 |
a connection failed |
61 |
""" |
|
0 | 62 |
|
63 |
class AuthenticationError(ConnectionError): |
|
5032 | 64 |
"""raised when when an attempt to establish a connection failed do to wrong |
65 |
connection information (login / password or other authentication token) |
|
4911
898c35be5873
#750055: make it easier to change post logout url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4270
diff
changeset
|
66 |
""" |
0 | 67 |
|
68 |
class BadConnectionId(ConnectionError): |
|
5032 | 69 |
"""raised when a bad connection id is given""" |
0 | 70 |
|
71 |
class UnknownEid(RepositoryError): |
|
72 |
"""the eid is not defined in the system tables""" |
|
73 |
msg = 'No entity with eid %s in the repository' |
|
74 |
||
75 |
class ETypeNotSupportedBySources(RepositoryError, InternalError): |
|
76 |
"""no source support an entity type""" |
|
77 |
msg = 'No source supports %r entity\'s type' |
|
78 |
||
3042
d2455badf7fb
[multi-sources] enhance relation'source detection to avoid inconsistency
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2850
diff
changeset
|
79 |
class MultiSourcesError(RepositoryError, InternalError): |
d2455badf7fb
[multi-sources] enhance relation'source detection to avoid inconsistency
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2850
diff
changeset
|
80 |
"""usually due to bad multisources configuration or rql query""" |
0 | 81 |
|
6211
e9d125fd1465
nicer error reporting for unique together constraints
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5426
diff
changeset
|
82 |
class UniqueTogetherError(RepositoryError): |
e9d125fd1465
nicer error reporting for unique together constraints
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5426
diff
changeset
|
83 |
"""raised when a unique_together constraint caused an IntegrityError""" |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
84 |
|
8265
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
85 |
|
0 | 86 |
# security exceptions ######################################################### |
87 |
||
88 |
class Unauthorized(SecurityError): |
|
89 |
"""raised when a user tries to perform an action without sufficient |
|
90 |
credentials |
|
91 |
""" |
|
92 |
msg = 'You are not allowed to perform this operation' |
|
93 |
msg1 = 'You are not allowed to perform %s operation on %s' |
|
94 |
var = None |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
95 |
|
0 | 96 |
def __str__(self): |
97 |
try: |
|
98 |
if self.args and len(self.args) == 2: |
|
99 |
return self.msg1 % self.args |
|
100 |
if self.args: |
|
101 |
return ' '.join(self.args) |
|
102 |
return self.msg |
|
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8609
diff
changeset
|
103 |
except Exception as ex: |
0 | 104 |
return str(ex) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
105 |
|
8602
d066ba3bb07d
[web] add a Forbidden exception
David Douard <david.douard@logilab.fr>
parents:
8265
diff
changeset
|
106 |
class Forbidden(SecurityError): |
d066ba3bb07d
[web] add a Forbidden exception
David Douard <david.douard@logilab.fr>
parents:
8265
diff
changeset
|
107 |
"""raised when a user tries to perform a forbidden action |
d066ba3bb07d
[web] add a Forbidden exception
David Douard <david.douard@logilab.fr>
parents:
8265
diff
changeset
|
108 |
""" |
d066ba3bb07d
[web] add a Forbidden exception
David Douard <david.douard@logilab.fr>
parents:
8265
diff
changeset
|
109 |
|
0 | 110 |
# source exceptions ########################################################### |
111 |
||
112 |
class EidNotInSource(SourceException): |
|
113 |
"""trying to access an object with a particular eid from a particular |
|
114 |
source has failed |
|
115 |
""" |
|
116 |
msg = 'No entity with eid %s in %s' |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
117 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
118 |
|
0 | 119 |
# registry exceptions ######################################################### |
120 |
||
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6491
diff
changeset
|
121 |
# pre 3.15 bw compat |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6491
diff
changeset
|
122 |
from logilab.common.registry import RegistryException, ObjectNotFound, NoSelectableObject |
0 | 123 |
|
124 |
class UnknownProperty(RegistryException): |
|
125 |
"""property found in database but unknown in registry""" |
|
126 |
||
127 |
# query exception ############################################################# |
|
128 |
||
129 |
class QueryError(CubicWebRuntimeError): |
|
130 |
"""a query try to do something it shouldn't""" |
|
131 |
||
132 |
class NotAnEntity(CubicWebRuntimeError): |
|
133 |
"""raised when get_entity is called for a column which doesn't contain |
|
134 |
a non final entity |
|
135 |
""" |
|
136 |
||
8265
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
137 |
class UndoTransactionException(QueryError): |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
138 |
"""Raised when undoing a transaction could not be performed completely. |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
139 |
|
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
140 |
Note that : |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
141 |
1) the partial undo operation might be acceptable |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
142 |
depending upon the final application |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
143 |
|
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
144 |
2) the undo operation can also fail with a `ValidationError` in |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
145 |
cases where the undoing breaks integrity constraints checked |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
146 |
immediately. |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
147 |
|
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
148 |
3) It might be that neither of those exception is raised but a |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
149 |
subsequent `commit` might raise a `ValidationError` in cases |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
150 |
where the undoing breaks integrity constraints checked at |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
151 |
commit time. |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
152 |
|
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
153 |
:type txuuix: int |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
154 |
:param txuuid: Unique identifier of the partialy undone transaction |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
155 |
|
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
156 |
:type errors: list |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
157 |
:param errors: List of errors occured during undoing |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
158 |
""" |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
159 |
msg = u"The following error(s) occured while undoing transaction #%d : %s" |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
160 |
|
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
161 |
def __init__(self, txuuid, errors): |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
162 |
super(UndoTransactionException, self).__init__(txuuid, errors) |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
163 |
self.txuuid = txuuid |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
164 |
self.errors = errors |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
165 |
|
0 | 166 |
# tools exceptions ############################################################ |
167 |
||
168 |
class ExecutionError(Exception): |
|
169 |
"""server execution control error (already started, not running...)""" |
|
170 |
||
6491
ee9a10b6620e
pylint option update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6347
diff
changeset
|
171 |
# pylint: disable=W0611 |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
172 |
from logilab.common.clcommands import BadCommandUsage |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6491
diff
changeset
|
173 |