arvados.errors

 1# Copyright (C) The Arvados Authors. All rights reserved.
 2#
 3# SPDX-License-Identifier: Apache-2.0
 4
 5# errors.py - Arvados-specific exceptions.
 6
 7import json
 8
 9from apiclient import errors as apiclient_errors
10from collections import OrderedDict
11
12class ApiError(apiclient_errors.HttpError):
13    def _get_reason(self):
14        try:
15            return '; '.join(json.loads(self.content.decode('utf-8'))['errors'])
16        except (KeyError, TypeError, ValueError):
17            return super(ApiError, self)._get_reason()
18
19
20class KeepRequestError(Exception):
21    """Base class for errors accessing Keep services."""
22    def __init__(self, message='', request_errors=(), label=""):
23        """KeepRequestError(message='', request_errors=(), label="")
24
25        :message:
26          A human-readable message describing what Keep operation
27          failed.
28
29        :request_errors:
30          An iterable that yields 2-tuples of keys (where the key refers to
31          some operation that was attempted) to the error encountered when
32          talking to it--either an exception, or an HTTP response object.
33          These will be packed into an OrderedDict, available through the
34          request_errors() method.
35
36        :label:
37          A label indicating the type of value in the 'key' position of request_errors.
38
39        """
40        self.label = label
41        self._request_errors = OrderedDict(request_errors)
42        if self._request_errors:
43            exc_reports = [self._format_error(*err_pair)
44                           for err_pair in self._request_errors.items()]
45            base_msg = "{}: {}".format(message, "; ".join(exc_reports))
46        else:
47            base_msg = message
48        super(KeepRequestError, self).__init__(base_msg)
49        self.message = message
50
51    def _format_error(self, key, error):
52        if isinstance(error, HttpError):
53            err_fmt = "{} {} responded with {e.status_code} {e.reason}"
54        else:
55            err_fmt = "{} {} raised {e.__class__.__name__} ({e})"
56        return err_fmt.format(self.label, key, e=error)
57
58    def request_errors(self):
59        """request_errors() -> OrderedDict
60
61        The keys of the dictionary are described by `self.label`
62        The corresponding value is the exception raised when sending the
63        request to it."""
64        return self._request_errors
65
66
67class HttpError(Exception):
68    def __init__(self, status_code, reason):
69        self.status_code = status_code
70        self.reason = reason
71
72
73class ArgumentError(Exception):
74    pass
75class SyntaxError(Exception):
76    pass
77class AssertionError(Exception):
78    pass
79class CommandFailedError(Exception):
80    pass
81class KeepReadError(KeepRequestError):
82    pass
83class KeepWriteError(KeepRequestError):
84    pass
85class KeepCacheError(KeepRequestError):
86    pass
87class NotFoundError(KeepReadError):
88    pass
89class NotImplementedError(Exception):
90    pass
91class NoKeepServersError(Exception):
92    pass
93class StaleWriterStateError(Exception):
94    pass
95class FeatureNotEnabledError(Exception):
96    pass
class ApiError(googleapiclient.errors.HttpError):
13class ApiError(apiclient_errors.HttpError):
14    def _get_reason(self):
15        try:
16            return '; '.join(json.loads(self.content.decode('utf-8'))['errors'])
17        except (KeyError, TypeError, ValueError):
18            return super(ApiError, self)._get_reason()

HTTP data was invalid or unexpected.

class KeepRequestError(builtins.Exception):
21class KeepRequestError(Exception):
22    """Base class for errors accessing Keep services."""
23    def __init__(self, message='', request_errors=(), label=""):
24        """KeepRequestError(message='', request_errors=(), label="")
25
26        :message:
27          A human-readable message describing what Keep operation
28          failed.
29
30        :request_errors:
31          An iterable that yields 2-tuples of keys (where the key refers to
32          some operation that was attempted) to the error encountered when
33          talking to it--either an exception, or an HTTP response object.
34          These will be packed into an OrderedDict, available through the
35          request_errors() method.
36
37        :label:
38          A label indicating the type of value in the 'key' position of request_errors.
39
40        """
41        self.label = label
42        self._request_errors = OrderedDict(request_errors)
43        if self._request_errors:
44            exc_reports = [self._format_error(*err_pair)
45                           for err_pair in self._request_errors.items()]
46            base_msg = "{}: {}".format(message, "; ".join(exc_reports))
47        else:
48            base_msg = message
49        super(KeepRequestError, self).__init__(base_msg)
50        self.message = message
51
52    def _format_error(self, key, error):
53        if isinstance(error, HttpError):
54            err_fmt = "{} {} responded with {e.status_code} {e.reason}"
55        else:
56            err_fmt = "{} {} raised {e.__class__.__name__} ({e})"
57        return err_fmt.format(self.label, key, e=error)
58
59    def request_errors(self):
60        """request_errors() -> OrderedDict
61
62        The keys of the dictionary are described by `self.label`
63        The corresponding value is the exception raised when sending the
64        request to it."""
65        return self._request_errors

Base class for errors accessing Keep services.

KeepRequestError(message='', request_errors=(), label='')
23    def __init__(self, message='', request_errors=(), label=""):
24        """KeepRequestError(message='', request_errors=(), label="")
25
26        :message:
27          A human-readable message describing what Keep operation
28          failed.
29
30        :request_errors:
31          An iterable that yields 2-tuples of keys (where the key refers to
32          some operation that was attempted) to the error encountered when
33          talking to it--either an exception, or an HTTP response object.
34          These will be packed into an OrderedDict, available through the
35          request_errors() method.
36
37        :label:
38          A label indicating the type of value in the 'key' position of request_errors.
39
40        """
41        self.label = label
42        self._request_errors = OrderedDict(request_errors)
43        if self._request_errors:
44            exc_reports = [self._format_error(*err_pair)
45                           for err_pair in self._request_errors.items()]
46            base_msg = "{}: {}".format(message, "; ".join(exc_reports))
47        else:
48            base_msg = message
49        super(KeepRequestError, self).__init__(base_msg)
50        self.message = message

KeepRequestError(message=’’, request_errors=(), label="")

:message: A human-readable message describing what Keep operation failed.

:request_errors: An iterable that yields 2-tuples of keys (where the key refers to some operation that was attempted) to the error encountered when talking to it--either an exception, or an HTTP response object. These will be packed into an OrderedDict, available through the request_errors() method.

:label: A label indicating the type of value in the ‘key’ position of request_errors.

label
message
def request_errors(self):
59    def request_errors(self):
60        """request_errors() -> OrderedDict
61
62        The keys of the dictionary are described by `self.label`
63        The corresponding value is the exception raised when sending the
64        request to it."""
65        return self._request_errors

request_errors() -> OrderedDict

The keys of the dictionary are described by self.label The corresponding value is the exception raised when sending the request to it.

class HttpError(builtins.Exception):
68class HttpError(Exception):
69    def __init__(self, status_code, reason):
70        self.status_code = status_code
71        self.reason = reason

Common base class for all non-exit exceptions.

HttpError(status_code, reason)
69    def __init__(self, status_code, reason):
70        self.status_code = status_code
71        self.reason = reason
status_code
reason
class ArgumentError(builtins.Exception):
74class ArgumentError(Exception):
75    pass

Common base class for all non-exit exceptions.

class SyntaxError(builtins.Exception):
76class SyntaxError(Exception):
77    pass

Common base class for all non-exit exceptions.

class AssertionError(builtins.Exception):
78class AssertionError(Exception):
79    pass

Common base class for all non-exit exceptions.

class CommandFailedError(builtins.Exception):
80class CommandFailedError(Exception):
81    pass

Common base class for all non-exit exceptions.

class KeepReadError(KeepRequestError):
82class KeepReadError(KeepRequestError):
83    pass

Base class for errors accessing Keep services.

class KeepWriteError(KeepRequestError):
84class KeepWriteError(KeepRequestError):
85    pass

Base class for errors accessing Keep services.

class KeepCacheError(KeepRequestError):
86class KeepCacheError(KeepRequestError):
87    pass

Base class for errors accessing Keep services.

class NotFoundError(KeepReadError):
88class NotFoundError(KeepReadError):
89    pass

Base class for errors accessing Keep services.

class NotImplementedError(builtins.Exception):
90class NotImplementedError(Exception):
91    pass

Common base class for all non-exit exceptions.

class NoKeepServersError(builtins.Exception):
92class NoKeepServersError(Exception):
93    pass

Common base class for all non-exit exceptions.

class StaleWriterStateError(builtins.Exception):
94class StaleWriterStateError(Exception):
95    pass

Common base class for all non-exit exceptions.

class FeatureNotEnabledError(builtins.Exception):
96class FeatureNotEnabledError(Exception):
97    pass

Common base class for all non-exit exceptions.