-
Notifications
You must be signed in to change notification settings - Fork 153
/
errors.go
103 lines (87 loc) · 2.61 KB
/
errors.go
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
// Copyright (c) 2013-2015 The btcsuite developers
// Copyright (c) 2016-2018 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package legacyrpc
import (
"fmt"
"github.com/decred/dcrd/dcrjson"
"github.com/decred/dcrwallet/errors"
)
func convertError(err error) *dcrjson.RPCError {
if err, ok := err.(*dcrjson.RPCError); ok {
return err
}
code := dcrjson.ErrRPCWallet
if err, ok := err.(*errors.Error); ok {
switch err.Kind {
case errors.Bug:
code = dcrjson.ErrRPCInternal.Code
case errors.Encoding:
code = dcrjson.ErrRPCInvalidParameter
case errors.Locked:
code = dcrjson.ErrRPCWalletUnlockNeeded
case errors.Passphrase:
code = dcrjson.ErrRPCWalletPassphraseIncorrect
case errors.NoPeers:
code = dcrjson.ErrRPCClientNotConnected
case errors.InsufficientBalance:
code = dcrjson.ErrRPCWalletInsufficientFunds
}
}
return &dcrjson.RPCError{
Code: code,
Message: err.Error(),
}
}
func rpcError(code dcrjson.RPCErrorCode, err error) *dcrjson.RPCError {
return &dcrjson.RPCError{
Code: code,
Message: err.Error(),
}
}
func rpcErrorf(code dcrjson.RPCErrorCode, format string, args ...interface{}) *dcrjson.RPCError {
return &dcrjson.RPCError{
Code: code,
Message: fmt.Sprintf(format, args...),
}
}
// Errors variables that are defined once here to avoid duplication.
var (
errUnloadedWallet = &dcrjson.RPCError{
Code: dcrjson.ErrRPCWallet,
Message: "request requires a wallet but wallet has not loaded yet",
}
errRPCClientNotConnected = &dcrjson.RPCError{
Code: dcrjson.ErrRPCClientNotConnected,
Message: "disconnected from consensus RPC",
}
errNoNetwork = &dcrjson.RPCError{
Code: dcrjson.ErrRPCClientNotConnected,
Message: "disconnected from network",
}
errAccountNotFound = &dcrjson.RPCError{
Code: dcrjson.ErrRPCWalletInvalidAccountName,
Message: "account not found",
}
errAddressNotInWallet = &dcrjson.RPCError{
Code: dcrjson.ErrRPCWallet,
Message: "address not found in wallet",
}
errNotImportedAccount = &dcrjson.RPCError{
Code: dcrjson.ErrRPCWallet,
Message: "imported addresses must belong to the imported account",
}
errNeedPositiveAmount = &dcrjson.RPCError{
Code: dcrjson.ErrRPCInvalidParameter,
Message: "amount must be positive",
}
errWalletUnlockNeeded = &dcrjson.RPCError{
Code: dcrjson.ErrRPCWalletUnlockNeeded,
Message: "enter the wallet passphrase with walletpassphrase first",
}
errReservedAccountName = &dcrjson.RPCError{
Code: dcrjson.ErrRPCInvalidParameter,
Message: "account name is reserved by RPC server",
}
)