1
// Copyright 2013 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
9
"launchpad.net/juju-core/rpc"
12
// Error is the type of error returned by any call to the state API
18
func (e *Error) Error() string {
22
func (e *Error) ErrorCode() string {
26
var _ rpc.ErrorCoder = (*Error)(nil)
28
// GoString implements fmt.GoStringer. It means that a *Error shows its
29
// contents correctly when printed with %#v.
30
func (e Error) GoString() string {
31
return fmt.Sprintf("¶ms.Error{%q, %q}", e.Code, e.Message)
34
// The Code constants hold error codes for some kinds of error.
36
CodeNotFound = "not found"
37
CodeUnauthorized = "unauthorized access"
38
CodeCannotEnterScope = "cannot enter scope"
39
CodeCannotEnterScopeYet = "cannot enter scope yet"
40
CodeExcessiveContention = "excessive contention"
41
CodeUnitHasSubordinates = "unit has subordinates"
42
CodeNotAssigned = "not assigned"
43
CodeStopped = "stopped"
44
CodeHasAssignedUnits = "machine has assigned units"
47
// ErrCode returns the error code associated with
48
// the given error, or the empty string if there
50
func ErrCode(err error) string {
51
if err, _ := err.(rpc.ErrorCoder); err != nil {
52
return err.ErrorCode()
57
// clientError maps errors returned from an RPC call into local errors with
58
// appropriate values.
59
func ClientError(err error) error {
60
rerr, ok := err.(*rpc.RequestError)
64
// We use our own error type rather than rpc.ServerError
65
// because we don't want the code or the "server error" prefix
66
// within the error message. Also, it's best not to make clients
67
// know that we're using the rpc package.
69
Message: rerr.Message,