author | Nicolas Chauvat <nicolas.chauvat@logilab.fr> |
Sun, 08 Nov 2009 19:37:08 +0100 | |
branch | stable |
changeset 3807 | 8ae53322ffcc |
parent 3162 | d6ae24439bee |
child 4212 | ab6573088b4a |
permissions | -rw-r--r-- |
0 | 1 |
"""Exceptions shared by different cubicweb packages. |
2 |
||
3 |
||
4 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
5 |
:copyright: 2001-2009 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 |
|
23 |
return ' '.join(str(arg) for arg in self.args) |
|
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 |
|
48 |
a connection failed""" |
|
49 |
||
50 |
class AuthenticationError(ConnectionError): |
|
51 |
"""raised when a bad connection id is given or when an attempt to establish |
|
52 |
a connection failed""" |
|
53 |
||
54 |
class BadConnectionId(ConnectionError): |
|
55 |
"""raised when a bad connection id is given or when an attempt to establish |
|
56 |
a connection failed""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
57 |
|
0 | 58 |
BadSessionId = BadConnectionId # XXX bw compat for pyro connections |
59 |
||
60 |
class UnknownEid(RepositoryError): |
|
61 |
"""the eid is not defined in the system tables""" |
|
62 |
msg = 'No entity with eid %s in the repository' |
|
63 |
||
64 |
class ETypeNotSupportedBySources(RepositoryError, InternalError): |
|
65 |
"""no source support an entity type""" |
|
66 |
msg = 'No source supports %r entity\'s type' |
|
67 |
||
3042
d2455badf7fb
[multi-sources] enhance relation'source detection to avoid inconsistency
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2850
diff
changeset
|
68 |
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
|
69 |
"""usually due to bad multisources configuration or rql query""" |
0 | 70 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
71 |
|
0 | 72 |
# security exceptions ######################################################### |
73 |
||
74 |
class Unauthorized(SecurityError): |
|
75 |
"""raised when a user tries to perform an action without sufficient |
|
76 |
credentials |
|
77 |
""" |
|
78 |
msg = 'You are not allowed to perform this operation' |
|
79 |
msg1 = 'You are not allowed to perform %s operation on %s' |
|
80 |
var = None |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
81 |
|
0 | 82 |
def __str__(self): |
83 |
try: |
|
84 |
if self.args and len(self.args) == 2: |
|
85 |
return self.msg1 % self.args |
|
86 |
if self.args: |
|
87 |
return ' '.join(self.args) |
|
88 |
return self.msg |
|
89 |
except Exception, ex: |
|
90 |
return str(ex) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
91 |
|
0 | 92 |
# source exceptions ########################################################### |
93 |
||
94 |
class EidNotInSource(SourceException): |
|
95 |
"""trying to access an object with a particular eid from a particular |
|
96 |
source has failed |
|
97 |
""" |
|
98 |
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
|
99 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
100 |
|
0 | 101 |
# registry exceptions ######################################################### |
102 |
||
103 |
class RegistryException(CubicWebException): |
|
104 |
"""raised when an unregistered view is called""" |
|
105 |
||
106 |
class RegistryNotFound(RegistryException): |
|
107 |
"""raised when an unknown registry is requested |
|
108 |
||
109 |
this is usually a programming/typo error... |
|
110 |
""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
111 |
|
0 | 112 |
class ObjectNotFound(RegistryException): |
113 |
"""raised when an unregistered object is requested |
|
114 |
||
115 |
this may be a programming/typo or a misconfiguration error |
|
116 |
""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
117 |
|
0 | 118 |
class NoSelectableObject(RegistryException): |
119 |
"""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
|
120 |
one is applicable to the result set |
0 | 121 |
""" |
122 |
||
123 |
class UnknownProperty(RegistryException): |
|
124 |
"""property found in database but unknown in registry""" |
|
125 |
||
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
|
126 |
class RegistryOutOfDate(RegistryException): |
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
|
127 |
"""raised when a source file modification is detected""" |
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
|
128 |
|
0 | 129 |
# query exception ############################################################# |
130 |
||
131 |
class QueryError(CubicWebRuntimeError): |
|
132 |
"""a query try to do something it shouldn't""" |
|
133 |
||
134 |
class NotAnEntity(CubicWebRuntimeError): |
|
135 |
"""raised when get_entity is called for a column which doesn't contain |
|
136 |
a non final entity |
|
137 |
""" |
|
138 |
||
139 |
# tools exceptions ############################################################ |
|
140 |
||
141 |
class ExecutionError(Exception): |
|
142 |
"""server execution control error (already started, not running...)""" |
|
143 |
||
144 |
# pylint: disable-msg=W0611 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
145 |
from logilab.common.clcommands import BadCommandUsage |