-
Notifications
You must be signed in to change notification settings - Fork 225
Expand file tree
/
Copy pathexceptions.py
More file actions
162 lines (123 loc) · 4.52 KB
/
exceptions.py
File metadata and controls
162 lines (123 loc) · 4.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
"""
Module for all xblock exception classes
"""
import json
from webob import Response
class XBlockNotFoundError(Exception):
"""
Raised to indicate that an XBlock could not be found with the requested usage_id
"""
def __init__(self, usage_id):
# Exception is an old-style class, so can't use super
Exception.__init__(self)
self.message = f"Unable to load an xblock for usage_id {usage_id!r}"
class XBlockSaveError(Exception):
"""
Raised to indicate an error in saving an XBlock
"""
def __init__(self, saved_fields, dirty_fields, message=None):
"""
Create a new XBlockSaveError
`saved_fields` - a set of fields that were successfully
saved before the error occurred
`dirty_fields` - a set of fields that were left dirty after the save
"""
# Exception is an old-style class, so can't use super
Exception.__init__(self)
self.message = message
self.saved_fields = saved_fields
self.dirty_fields = dirty_fields
class KeyValueMultiSaveError(Exception):
"""
Raised to indicated an error in saving multiple fields in a KeyValueStore
"""
def __init__(self, saved_field_names):
"""
Create a new KeyValueMultiSaveError
`saved_field_names` - an iterable of field names (strings) that were
successfully saved before the exception occurred
"""
# Exception is an old-style class, so can't use super
Exception.__init__(self)
self.saved_field_names = saved_field_names
class InvalidScopeError(Exception):
"""
Raised to indicated that operating on the supplied scope isn't allowed by a KeyValueStore
"""
def __init__(self, invalid_scope, valid_scopes=None):
super().__init__()
if valid_scopes:
self.message = "Invalid scope: {}. Valid scopes are: {}".format(
invalid_scope,
valid_scopes,
)
else:
self.message = f"Invalid scope: {invalid_scope}"
class NoSuchViewError(Exception):
"""
Raised to indicate that the view requested was not found.
"""
def __init__(self, block, view_name):
"""
Create a new NoSuchViewError
:param block: The XBlock without a view
:param view_name: The name of the view that couldn't be found
"""
# Can't use super because Exception is an old-style class
Exception.__init__(self)
self.message = f"Unable to find view {view_name!r} on block {block!r}"
class NoSuchHandlerError(Exception):
"""
Raised to indicate that the requested handler was not found.
"""
class NoSuchServiceError(Exception):
"""
Raised to indicate that a requested service was not found.
"""
class NoSuchUsage(Exception):
"""Raised by :meth:`.IdReader.get_definition_id` if the usage doesn't exist."""
class NoSuchDefinition(Exception):
"""Raised by :meth:`.IdReader.get_block_type` if the definition doesn't exist."""
class JsonHandlerError(Exception):
"""
Raised by a function decorated with XBlock.json_handler to indicate that an
error response should be returned.
"""
def __init__(self, status_code, message):
super().__init__()
self.status_code = status_code
self.message = message
def get_response(self, **kwargs):
"""
Returns a Response object containing this object's status code and a
JSON object containing the key "error" with the value of this object's
error message in the body. Keyword args are passed through to
the Response.
"""
return Response(
json.dumps({"error": self.message}),
status_code=self.status_code,
content_type="application/json",
charset="utf-8",
**kwargs
)
class DisallowedFileError(Exception):
"""
Raised by :meth:`.XBlock.open_local_resource` or :meth:`.XBlockAside.open_local_resource`.
"""
class FieldDataDeprecationWarning(DeprecationWarning):
"""Warning for use of deprecated _field_data accessor"""
class UserIdDeprecationWarning(DeprecationWarning):
"""Warning for use of deprecated user_id accessor"""
class XBlockParseException(Exception):
"""
Raised if parsing the XBlock olx fails.
"""
class NotFoundError(Exception):
"""
Raised when a requested XBlock resource or entity cannot be found.
"""
class ProcessingError(Exception):
"""
Raised when an error occurs while processing an XBlock request.
"""