1 # errors.py - Arvados-specific exceptions.
6 from apiclient import errors as apiclient_errors
7 from collections import OrderedDict
9 class ApiError(apiclient_errors.HttpError):
10 def _get_reason(self):
12 return '; '.join(json.loads(self.content)['errors'])
13 except (KeyError, TypeError, ValueError):
14 return super(ApiError, self)._get_reason()
17 class KeepRequestError(Exception):
18 """Base class for errors accessing Keep services."""
19 def __init__(self, message='', service_errors=()):
20 """KeepRequestError(message='', service_errors=())
23 * message: A human-readable message describing what Keep operation
25 * service_errors: An iterable that yields 2-tuples of Keep
26 service URLs to the error encountered when talking to
27 it--either an exception, or an HTTP response object. These
28 will be packed into an OrderedDict, available through the
29 service_errors() method.
31 self._service_errors = OrderedDict(service_errors)
32 if self._service_errors:
33 exc_reports = [self._format_error(*err_pair)
34 for err_pair in self._service_errors.iteritems()]
35 base_msg = "{}: {}".format(message, "; ".join(exc_reports))
38 super(KeepRequestError, self).__init__(base_msg)
39 self.message = message
41 def _format_error(self, service_root, error):
42 if isinstance(error, requests.Response):
43 err_fmt = "{} responded with {e.status_code} {e.reason}"
45 err_fmt = "{} raised {e.__class__.__name__} ({e})"
46 return err_fmt.format(service_root, e=error)
48 def service_errors(self):
49 """service_errors() -> OrderedDict
51 The keys of the dictionary are Keep service URLs.
52 The corresponding value is the exception raised when sending the
54 return self._service_errors
57 class ArgumentError(Exception):
59 class SyntaxError(Exception):
61 class AssertionError(Exception):
63 class CommandFailedError(Exception):
65 class KeepReadError(KeepRequestError):
67 class KeepWriteError(KeepRequestError):
69 class NotFoundError(KeepReadError):
71 class NotImplementedError(Exception):
73 class NoKeepServersError(Exception):
75 class StaleWriterStateError(Exception):
77 class FeatureNotEnabledError(Exception):