-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
47 lines (39 loc) · 991 Bytes
/
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
package ibc
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
// IBC errors reserve 200 - 299.
CodeInvalidSequence sdk.CodeType = 200
CodeIdenticalChains sdk.CodeType = 201
CodeUnknownRequest sdk.CodeType = sdk.CodeUnknownRequest
)
func codeToDefaultMsg(code sdk.CodeType) string {
switch code {
case CodeInvalidSequence:
return "Invalid IBC packet sequence"
case CodeIdenticalChains:
return "Source and destination chain cannot be identical"
default:
return sdk.CodeToDefaultMsg(code)
}
}
func ErrInvalidSequence() sdk.Error {
return newError(CodeInvalidSequence, "")
}
func ErrIdenticalChains() sdk.Error {
return newError(CodeIdenticalChains, "")
}
// -------------------------
// Helpers
func newError(code sdk.CodeType, msg string) sdk.Error {
msg = msgOrDefaultMsg(msg, code)
return sdk.NewError(code, msg)
}
func msgOrDefaultMsg(msg string, code sdk.CodeType) string {
if msg != "" {
return msg
} else {
return codeToDefaultMsg(code)
}
}