forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
59 lines (47 loc) · 1.38 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
//nolint
package bank
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Bank errors reserve 100 ~ 199.
const (
DefaultCodespace sdk.CodespaceType = 2
CodeInvalidInput sdk.CodeType = 101
CodeInvalidOutput sdk.CodeType = 102
)
// NOTE: Don't stringer this, we'll put better messages in later.
func codeToDefaultMsg(code sdk.CodeType) string {
switch code {
case CodeInvalidInput:
return "invalid input coins"
case CodeInvalidOutput:
return "invalid output coins"
default:
return sdk.CodeToDefaultMsg(code)
}
}
//----------------------------------------
// Error constructors
func ErrInvalidInput(codespace sdk.CodespaceType, msg string) sdk.Error {
return newError(codespace, CodeInvalidInput, msg)
}
func ErrNoInputs(codespace sdk.CodespaceType) sdk.Error {
return newError(codespace, CodeInvalidInput, "")
}
func ErrInvalidOutput(codespace sdk.CodespaceType, msg string) sdk.Error {
return newError(codespace, CodeInvalidOutput, msg)
}
func ErrNoOutputs(codespace sdk.CodespaceType) sdk.Error {
return newError(codespace, CodeInvalidOutput, "")
}
//----------------------------------------
func msgOrDefaultMsg(msg string, code sdk.CodeType) string {
if msg != "" {
return msg
}
return codeToDefaultMsg(code)
}
func newError(codespace sdk.CodespaceType, code sdk.CodeType, msg string) sdk.Error {
msg = msgOrDefaultMsg(msg, code)
return sdk.NewError(codespace, code, msg)
}