forked from juju/txjuju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.py
59 lines (42 loc) · 1.73 KB
/
errors.py
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
# Copyright 2016 Canonical Limited. All rights reserved.
class CLIError(Exception):
"""Raised when juju fails."""
def __init__(self, out, err, code=None, signal=None):
if code is not None:
reason = "exit code {}".format(code)
if signal is not None:
reason = "signal {}".format(signal)
msg = ("juju ended with {} (out='{}', err='{}')"
).format(reason, out, err)
super(CLIError, self).__init__(msg)
self.out = out
self.err = err
self.code = code
self.signal = signal
class APIRequestError(Exception):
"""The server returned an error for a given API request."""
def __init__(self, error, code):
"""
@param error: The human-oriented error message.
@param code: The machine-oriented error code (a string, see
juju/apiserver/params/apierror.go).
"""
msg = "{} (code: '{}')".format(error, code)
super(APIRequestError, self).__init__(msg)
self.error = error
self.code = code
class APIAuthError(APIRequestError):
"""Authorization error (e.g. login request with to wrong password)."""
class APIRetriableError(APIRequestError):
"""A server-side error that could be retried (e.g. juju is upgrading)."""
class AllWatcherStoppedError(APIRetriableError):
"""The server stopped the AllWatcher (probably due to a tools upgrade)."""
class InvalidAPIEndpointAddress(Exception):
"""The address is an invalid Juju API endpoint.
@param addr: The invalid address.
@type addr: C{str}
"""
def __init__(self, addr):
msg = "Invalid Juju endpoint: {}".format(addr)
super(InvalidAPIEndpointAddress, self).__init__(msg)
self.addr = addr