cosmos-sdk/x/ibc/errors.go
Dev Ojha 097dd8a164 tools: Add unparam linter (#1443)
* tools: Add unparam linter

unparam detects unused parameters in functions, and a parameter to
a function which only ever takes on one value. The latter is an
indication that more tests are required.

There are many nolints in this PR, as I believe that writing tests
to fix alot of these situations is out of scope for this PR / it
will be changed in future commits. There are some nolints for
when we have to comply to normal api's.

* crypto/keys no longer used by x/gov/client/rest/rest.go
2018-06-29 18:22:24 -04:00

51 lines
1.2 KiB
Go

package ibc
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
// IBC errors reserve 200 ~ 299.
const (
DefaultCodespace sdk.CodespaceType = 3
// 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)
}