forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
50 lines (42 loc) · 1.17 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
package ibc
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
// IBC errors reserve 200 ~ 299.
const (
DefaultCodespace sdk.CodespaceType = "ibc"
// 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)
}
}
// nolint
func ErrInvalidSequence(codespace sdk.CodespaceType) sdk.Error {
return newError(codespace, CodeInvalidSequence, "")
}
func ErrIdenticalChains(codespace sdk.CodespaceType) sdk.Error {
return newError(codespace, CodeIdenticalChains, "")
}
// -------------------------
// Helpers
// nolint: unparam
func newError(codespace sdk.CodespaceType, code sdk.CodeType, msg string) sdk.Error {
msg = msgOrDefaultMsg(msg, code)
return sdk.NewError(codespace, code, msg)
}
func msgOrDefaultMsg(msg string, code sdk.CodeType) string {
if msg != "" {
return msg
}
return codeToDefaultMsg(code)
}