author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 26 Apr 2010 17:11:59 +0200 | |
changeset 5409 | 1e074c6150fe |
parent 5274 | 16461f675734 |
child 5423 | e15abfdcce38 |
permissions | -rw-r--r-- |
0 | 1 |
"""Exceptions shared by different cubicweb packages. |
2 |
||
3 |
||
4 |
:organization: Logilab |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3162
diff
changeset
|
5 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
7 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 8 |
""" |
9 |
__docformat__ = "restructuredtext en" |
|
10 |
||
11 |
from yams import ValidationError |
|
12 |
||
13 |
# abstract exceptions ######################################################### |
|
14 |
||
15 |
class CubicWebException(Exception): |
|
16 |
"""base class for cubicweb server exception""" |
|
17 |
msg = "" |
|
18 |
def __str__(self): |
|
19 |
if self.msg: |
|
20 |
if self.args: |
|
21 |
return self.msg % tuple(self.args) |
|
22 |
return self.msg |
|
4270
189e4f5279e9
unicode(arg) else we may get some encoding exception
alex & cheb
parents:
4212
diff
changeset
|
23 |
return ' '.join(unicode(arg) for arg in self.args) |
0 | 24 |
|
25 |
||
26 |
class ConfigurationError(CubicWebException): |
|
27 |
"""a misconfiguration error""" |
|
28 |
||
29 |
class InternalError(CubicWebException): |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
30 |
"""base class for exceptions which should not occurs""" |
0 | 31 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
32 |
class SecurityError(CubicWebException): |
0 | 33 |
"""base class for cubicweb server security exception""" |
34 |
||
35 |
class RepositoryError(CubicWebException): |
|
36 |
"""base class for repository exceptions""" |
|
37 |
||
38 |
class SourceException(CubicWebException): |
|
39 |
"""base class for source exceptions""" |
|
40 |
||
41 |
class CubicWebRuntimeError(CubicWebException): |
|
42 |
"""base class for runtime exceptions""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
43 |
|
0 | 44 |
# repository exceptions ####################################################### |
45 |
||
46 |
class ConnectionError(RepositoryError): |
|
47 |
"""raised when a bad connection id is given or when an attempt to establish |
|
5032 | 48 |
a connection failed |
49 |
""" |
|
0 | 50 |
|
51 |
class AuthenticationError(ConnectionError): |
|
5032 | 52 |
"""raised when when an attempt to establish a connection failed do to wrong |
53 |
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
|
54 |
""" |
0 | 55 |
|
56 |
class BadConnectionId(ConnectionError): |
|
5032 | 57 |
"""raised when a bad connection id is given""" |
0 | 58 |
|
59 |
class UnknownEid(RepositoryError): |
|
60 |
"""the eid is not defined in the system tables""" |
|
61 |
msg = 'No entity with eid %s in the repository' |
|
62 |
||
63 |
class ETypeNotSupportedBySources(RepositoryError, InternalError): |
|
64 |
"""no source support an entity type""" |
|
65 |
msg = 'No source supports %r entity\'s type' |
|
66 |
||
3042
d2455badf7fb
[multi-sources] enhance relation'source detection to avoid inconsistency
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2850
diff
changeset
|
67 |
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
|
68 |
"""usually due to bad multisources configuration or rql query""" |
0 | 69 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
70 |
|
0 | 71 |
# security exceptions ######################################################### |
72 |
||
73 |
class Unauthorized(SecurityError): |
|
74 |
"""raised when a user tries to perform an action without sufficient |
|
75 |
credentials |
|
76 |
""" |
|
77 |
msg = 'You are not allowed to perform this operation' |
|
78 |
msg1 = 'You are not allowed to perform %s operation on %s' |
|
79 |
var = None |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
80 |
|
0 | 81 |
def __str__(self): |
82 |
try: |
|
83 |
if self.args and len(self.args) == 2: |
|
84 |
return self.msg1 % self.args |
|
85 |
if self.args: |
|
86 |
return ' '.join(self.args) |
|
87 |
return self.msg |
|
88 |
except Exception, ex: |
|
89 |
return str(ex) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
90 |
|
0 | 91 |
# source exceptions ########################################################### |
92 |
||
93 |
class EidNotInSource(SourceException): |
|
94 |
"""trying to access an object with a particular eid from a particular |
|
95 |
source has failed |
|
96 |
""" |
|
97 |
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
|
98 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
99 |
|
0 | 100 |
# registry exceptions ######################################################### |
101 |
||
102 |
class RegistryException(CubicWebException): |
|
103 |
"""raised when an unregistered view is called""" |
|
104 |
||
105 |
class RegistryNotFound(RegistryException): |
|
106 |
"""raised when an unknown registry is requested |
|
107 |
||
108 |
this is usually a programming/typo error... |
|
109 |
""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
110 |
|
0 | 111 |
class ObjectNotFound(RegistryException): |
112 |
"""raised when an unregistered object is requested |
|
113 |
||
114 |
this may be a programming/typo or a misconfiguration error |
|
115 |
""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
116 |
|
0 | 117 |
class NoSelectableObject(RegistryException): |
118 |
"""some views with the given vid have been found but no |
|
3144
a5deac822a13
Bugfix: message was not written in english
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2850
diff
changeset
|
119 |
one is applicable to the result set |
0 | 120 |
""" |
121 |
||
122 |
class UnknownProperty(RegistryException): |
|
123 |
"""property found in database but unknown in registry""" |
|
124 |
||
2651
3ad936634d2a
[registry] when a source file is changed, reset and reload the whole registry
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
125 |
|
0 | 126 |
# query exception ############################################################# |
127 |
||
128 |
class QueryError(CubicWebRuntimeError): |
|
129 |
"""a query try to do something it shouldn't""" |
|
130 |
||
131 |
class NotAnEntity(CubicWebRuntimeError): |
|
132 |
"""raised when get_entity is called for a column which doesn't contain |
|
133 |
a non final entity |
|
134 |
""" |
|
135 |
||
136 |
# tools exceptions ############################################################ |
|
137 |
||
138 |
class ExecutionError(Exception): |
|
139 |
"""server execution control error (already started, not running...)""" |
|
140 |
||
141 |
# pylint: disable-msg=W0611 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
142 |
from logilab.common.clcommands import BadCommandUsage |