cosmos-sdk/types/errors/errors.go

397 lines
13 KiB
Go
Raw Normal View History

package errors
import (
"fmt"
"reflect"
"github.com/pkg/errors"
)
// RootCodespace is the codespace for all errors defined in this package
const RootCodespace = "sdk"
// UndefinedCodespace when we explicitly declare no codespace
const UndefinedCodespace = "undefined"
var (
// errInternal should never be exposed, but we reserve this code for non-specified errors
errInternal = Register(UndefinedCodespace, 1, "internal")
// ErrTxDecode is returned if we cannot parse a transaction
ErrTxDecode = Register(RootCodespace, 2, "tx parse error")
// ErrInvalidSequence is used the sequence number (nonce) is incorrect
// for the signature
ErrInvalidSequence = Register(RootCodespace, 3, "invalid sequence")
// ErrUnauthorized is used whenever a request without sufficient
// authorization is handled.
ErrUnauthorized = Register(RootCodespace, 4, "unauthorized")
// ErrInsufficientFunds is used when the account cannot pay requested amount.
ErrInsufficientFunds = Register(RootCodespace, 5, "insufficient funds")
// ErrUnknownRequest to doc
ErrUnknownRequest = Register(RootCodespace, 6, "unknown request")
// ErrInvalidAddress to doc
ErrInvalidAddress = Register(RootCodespace, 7, "invalid address")
// ErrInvalidPubKey to doc
ErrInvalidPubKey = Register(RootCodespace, 8, "invalid pubkey")
// ErrUnknownAddress to doc
ErrUnknownAddress = Register(RootCodespace, 9, "unknown address")
// ErrInvalidCoins to doc
ErrInvalidCoins = Register(RootCodespace, 10, "invalid coins")
// ErrOutOfGas to doc
ErrOutOfGas = Register(RootCodespace, 11, "out of gas")
// ErrMemoTooLarge to doc
ErrMemoTooLarge = Register(RootCodespace, 12, "memo too large")
// ErrInsufficientFee to doc
ErrInsufficientFee = Register(RootCodespace, 13, "insufficient fee")
// ErrTooManySignatures to doc
ErrTooManySignatures = Register(RootCodespace, 14, "maximum number of signatures exceeded")
// ErrNoSignatures to doc
ErrNoSignatures = Register(RootCodespace, 15, "no signatures supplied")
// ErrJSONMarshal defines an ABCI typed JSON marshalling error
ErrJSONMarshal = Register(RootCodespace, 16, "failed to marshal JSON bytes")
// ErrJSONUnmarshal defines an ABCI typed JSON unmarshalling error
ErrJSONUnmarshal = Register(RootCodespace, 17, "failed to unmarshal JSON bytes")
// ErrInvalidRequest defines an ABCI typed error where the request contains
// invalid data.
ErrInvalidRequest = Register(RootCodespace, 18, "invalid request")
// ErrTxInMempoolCache defines an ABCI typed error where a tx already exists
// in the mempool.
ErrTxInMempoolCache = Register(RootCodespace, 19, "tx already in mempool")
// ErrMempoolIsFull defines an ABCI typed error where the mempool is full.
ErrMempoolIsFull = Register(RootCodespace, 20, "mempool is full")
// ErrTxTooLarge defines an ABCI typed error where tx is too large.
ErrTxTooLarge = Register(RootCodespace, 21, "tx too large")
// ErrKeyNotFound defines an error when the key doesn't exist
ErrKeyNotFound = Register(RootCodespace, 22, "key not found")
// ErrWrongPassword defines an error when the key password is invalid.
ErrWrongPassword = Register(RootCodespace, 23, "invalid account password")
// ErrorInvalidSigner defines an error when the tx intended signer does not match the given signer.
ErrorInvalidSigner = Register(RootCodespace, 24, "tx intended signer does not match the given signer")
// ErrorInvalidGasAdjustment defines an error for an invalid gas adjustment
ErrorInvalidGasAdjustment = Register(RootCodespace, 25, "invalid gas adjustment")
// ErrInvalidHeight defines an error for an invalid height
ErrInvalidHeight = Register(RootCodespace, 26, "invalid height")
// ErrInvalidVersion defines a general error for an invalid version
ErrInvalidVersion = Register(RootCodespace, 27, "invalid version")
// ErrInvalidChainID defines an error when the chain-id is invalid.
ErrInvalidChainID = Register(RootCodespace, 28, "invalid chain-id")
// ErrInvalidType defines an error an invalid type.
ErrInvalidType = Register(RootCodespace, 29, "invalid type")
// ErrTxTimeoutHeight defines an error for when a tx is rejected out due to an
// explicitly set timeout height.
ErrTxTimeoutHeight = Register(RootCodespace, 30, "tx timeout height")
// ErrUnknownExtensionOptions defines an error for unknown extension options.
ErrUnknownExtensionOptions = Register(RootCodespace, 31, "unknown extension options")
Put AccountSequence in SignerInfo (#6997) * WIP test the grounds * Update ADR020 * Fix compile errors * Fix ADR * Make ante tests pass * Fix remaining ante handler tests * Simplify code * Fix x/bank app_test * Fix tests * Remove useless accSeq from signerdata * Fix test * Update simapp/helpers/test_helpers.go Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * Update simapp/helpers/test_helpers.go Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * Update x/auth/client/cli/tx_multisign.go Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * Address rewview * Update x/auth/ante/sigverify.go Co-authored-by: Simon Warta <2603011+webmaster128@users.noreply.github.com> * Update x/auth/ante/sigverify_test.go Co-authored-by: Simon Warta <2603011+webmaster128@users.noreply.github.com> * Update x/auth/tx/builder_test.go Co-authored-by: Simon Warta <2603011+webmaster128@users.noreply.github.com> * Update x/auth/tx/builder_test.go Co-authored-by: Simon Warta <2603011+webmaster128@users.noreply.github.com> * Update x/auth/tx/direct_test.go Co-authored-by: Simon Warta <2603011+webmaster128@users.noreply.github.com> * Update x/auth/tx/builder_test.go Co-authored-by: Simon Warta <2603011+webmaster128@users.noreply.github.com> * AccSeq -> Seq * Address reviews * Better variable naming * Fix variable assign * Remove old SetSignerInfo * Fix test * proto-gen * Make proto-gen * Reput gw comment * Add Changelog * Update x/bank/app_test.go Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * Update x/bank/app_test.go Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: SaReN <sahithnarahari@gmail.com> Co-authored-by: Simon Warta <2603011+webmaster128@users.noreply.github.com>
2020-08-21 07:20:47 -07:00
// ErrWrongSequence defines an error where the account sequence defined in
// the signer info doesn't match the account's actual sequence number.
ErrWrongSequence = Register(RootCodespace, 32, "incorrect account sequence")
// ErrPackAny defines an error when packing a protobuf message to Any fails.
ErrPackAny = Register(RootCodespace, 33, "failed packing protobuf message to Any")
// ErrUnpackAny defines an error when unpacking a protobuf message from Any fails.
ErrUnpackAny = Register(RootCodespace, 34, "failed unpacking protobuf message from Any")
// ErrLogic defines an internal logic error, e.g. an invariant or assertion
// that is violated. It is a programmer error, not a user-facing error.
ErrLogic = Register(RootCodespace, 35, "internal logic error")
// ErrConflict defines a conflict error, e.g. when two goroutines try to access
// the same resource and one of them fails.
ErrConflict = Register(RootCodespace, 36, "conflict")
fix: Signature only flag bug on tx sign command 7632 (#8106) * fix: Signature only flag bug on tx sign command 7632 * Update client/context.go Co-authored-by: Cory <cjlevinson@gmail.com> * Update client/context.go Co-authored-by: Cory <cjlevinson@gmail.com> * use named return value and closure (#8111) This is to correctly handle deferred Close() calls on writable files. * set the right 'append' logic for signing transactions * cleanup * update tx.Sign interface by adding overwrite option * Update Changelog * sign command cleanup * implementation and changelog update * fix SignTx and tx.Sign calls * fix: sign didn't write to a file * update flags description * Add tx.Sign tests * fix grpc/server_test.go * Update client/tx/tx.go Co-authored-by: Cory <cjlevinson@gmail.com> * changelog update * Add test to verify matching signatures * cli_test: add integration tests for sign CMD * add output-file flag test * add flagAmino test * Update x/auth/client/cli/tx_sign.go Co-authored-by: Alessio Treglia <alessio@tendermint.com> * Update x/auth/client/cli/tx_sign.go * update amino serialization test * TestSign: adding unit test for signing with different modes * Add test with Multi Signers into Robert's TxSign PR (#8142) * Add test with Multi Signers * remove true false * Use SIGN_MODE_DIRECT * Fix litn * Use correct pubkeys * Correct accNum and seq * Use amino * cleanups * client.Sign: raise error when signing tx with multiple signers in Direct + added more unit tests * add more tests * Update client/tx/tx_test.go Co-authored-by: Cory <cjlevinson@gmail.com> * fix TestGetBroadcastCommand_WithoutOfflineFlag * Any.UnsafeSetCachedValue * fix note packed messages in tx builder * reorder unit tests * Changelog update * cleaning / linting * cli_tes: copy validator object instead of modifying it's shared codec * x/auth cli_test: remove custom codec creation in tests * Update CHANGELOG.md * updates to CHANGELOG.md * remove unused method * add new instance of transaction builder for TestSign Co-authored-by: Cory <cjlevinson@gmail.com> Co-authored-by: SaReN <sahithnarahari@gmail.com> Co-authored-by: Alessio Treglia <alessio@tendermint.com> Co-authored-by: Amaury <amaury.martiny@protonmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2020-12-14 13:44:15 -08:00
// ErrNotSupported is returned when we call a branch of a code which is currently not
// supported.
ErrNotSupported = Register(RootCodespace, 37, "feature not supported")
implement x/authz module (#7629) * WIP: Msg authorization module added * fixing errors * fixed errors * fixed module.go * Add msg_tests * fixes compile issues * fix test * fix test * Add msg types tests * Fix Getmsgs * fixed codec issue * Fix syntax issues * Fix keeper * fixed proto issues * Fix keeper tests * fixed router in keeper * Fix query proto * Fix cli txs * Add grpc query client implementation * Add grpc-keeper test * Add grpc query tests Add revoke and exec authorization cli commands * Fix linting issues * Fix cli query * fix lint errors * Add Genesis state * Fix query authorization * Review changes * Fix grant authorization handler * Add cli tests * Add cli tests * Fix genesis test * Fix issues * update module to use proto msg services * Add simultion tests * Fix lint * fix lint * WIP simulations * WIP simulations * add msg tests * Fix simulation * Fix errors * fix genesis import export * fix sim tests * fix sim * fix test * Register RegisterMsgServer * WIP * WIP * Update keeper test * change msg_authorization module name to authz * changed type conversion for serviceMsg * serviceMsg change to any * Fix issues * fix msg tests * fix errors * proto format * remove LegacyQuerierHandler * Use MsgServiceRouter * fix keeper-test * fix query authorizations * fix NewCmdSendAs * fix simtests * fix error * fix lint * fix lint * add tests for generic authorization * fix imports * format * Update error message * remove println * add query all grants * Add pagination for queries * format * fix lint * review changes * fix grpc tests * add pagination to cli query * review changes * replace panic with error * lint * fix errors * fix tests * remove gogoproto extensions * update function doc * review changes * fix errors * fix query flags * fix grpc query test * init service-msg * remove unsed field * add proto-codec for simulations * fix codec issue * update authz simulations * change msgauth to authz * add check for invalid msg-type * change expiration flag to Unix * doc * update module.go * fix sims * fix grant-authorization sims * fix error * fix error * add build flag * fix codec issue * rename * review changes * format * review changes * go.mod * refactor * proto-gen * Update x/authz/keeper/grpc_query_test.go Co-authored-by: Amaury <amaury.martiny@protonmail.com> * Update x/authz/keeper/grpc_query_test.go Co-authored-by: Amaury <amaury.martiny@protonmail.com> * Update x/authz/keeper/grpc_query_test.go Co-authored-by: Amaury <amaury.martiny@protonmail.com> * Fix review comments * fix protogen * Follow Msg...Request style for msg requests * update comment * Fix error codes * fix review comment * improve msg validations * Handle error in casting msgs * rename actor => grantStoreKey * add godoc * add godoc * Fix simulations * Fix cli, cli_tests * Fix simulations * rename to GetOrRevokeAuthorization * Move events to keeper * Fix fmt * Update x/authz/client/cli/tx.go Co-authored-by: Amaury <amaury.martiny@protonmail.com> * rename actor * fix lint Co-authored-by: atheesh <atheesh@vitwit.com> Co-authored-by: atheeshp <59333759+atheeshp@users.noreply.github.com> Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com> Co-authored-by: MD Aleem <72057206+aleem1413@users.noreply.github.com> Co-authored-by: Anil Kumar Kammari <anil@vitwit.com>
2021-01-25 08:41:30 -08:00
// ErrNotFound defines an error when requested entity doesn't exist in the state.
ErrNotFound = Register(RootCodespace, 38, "not found")
Remove bech32 PubKey support (#7477) * Move PubKey bech32 to legacy package and migrate the usage where possible * update /server * wip * move proto json encoding helper functions to internal * update internal/marshal * wip * update sections which needs legacybech32 * update validators output * fix conflicts * slashing update * add more tests and helper function for ANY JSON serialization * update slashing * Update function documentation * Rename code any-marshal helper functions * Update pubkey unpacking test * Update test comments * solve TestDecodeStore * solve legacytx issues * all code compiles * keyring tests * keyring cleanup * remove AssertMsg * fix some tests * fix add_ledger_test.go * update cli tests * debug cli test * rename clashed bech32 names * linter fixes * update tmservice tests * linter: update legacy deprecated checks * fix names * linting * legacybech32 pubkey type rename * fix staking client * fix test compilation * fix TestGetCmdQuerySigningInfo * rename NewIfcJSONAnyMarshaler * keyring: remove duplicated information from multinfo structure * todo cleanups * Update Changelog * remove some legacybech32 from tests * remove todos * remove printlnJSON from /server CLI and amino encoding * remove protocdc.MarshalJSON * client/show remove duplicated function * remove protocdc package * comment update * remove legacybech32.MustMarshalPubKey from a test * add todo * fix TestPublicKeyUnsafe test * review update * fix bech32 UnmarshalPubKey * Use codec.MarshalIfcJSON * fix linter issues * merging conflict: fix codec.Unmarshal calls * cleanups * Update CHANGELOG.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Reword changelog updates * use pubkey.String for comparison in Test_runAddCmdLedgerWithCustomCoinType * Update GetCmdQuerySigningInfo example * cli: update keys add docs * Add errors AsOf and errors.ErrIO type * restore multisigPubKeyInfo structure bring it back to multiInfo struct * Update codec/proto_codec.go Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com> * Update crypto/keys/ed25519/ed25519_test.go Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com> * Update codec/proto_codec.go Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com> * move pubkey any marshaling tests * Apply suggestions from code review Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com> * review updates * adding missing return * errors: use IsOf instead of AsOf * keyring: add a correct check for key not found in keyring.Get * add checkKeyNotFound * fix linter issues * fix: keyring key not found check * fix keyring tests * fix linting issues * cli tests * fix: 'simd keys show <key> -p' * fix: TestVerifyMultisignature * rename keyring Bech32... functions to Mk... * fix RunAddCmd * Update pubkey display * wip * add more tests * udate keyring output tests * remove todo from ledger tests * rename MkKeyOutput * Changelog update * solve liner issues * add link to github issue Co-authored-by: Aaron Craelius <aaron@regen.network> Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com>
2021-03-25 07:53:22 -07:00
// ErrIO should be used to wrap internal errors caused by external operation.
// Examples: not DB domain error, file writing etc...
ErrIO = Register(RootCodespace, 39, "Internal IO error")
// ErrPanic is only set when we recover from a panic, so we know to
// redact potentially sensitive system info
ErrPanic = Register(UndefinedCodespace, 111222, "panic")
feat: Non-zero Default Fees (#9371) <!-- < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < ☺ v ✰ Thanks for creating a PR! ✰ v Before smashing the submit button please review the checkboxes. v If a checkbox is n/a - please still include it but + a little note why ☺ > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > --> ## Description <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> closes: #9106 --- Before we can merge this PR, please make sure that all the following items have been checked off. If any of the checklist items are not applicable, please leave them but write a little note why. - [x] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] Linked to Github issue with discussion and accepted design OR link to spec that describes this work. - [ ] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules/structure.md). - [ ] Wrote unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] Updated relevant documentation (`docs/`) or specification (`x/<module>/spec/`) - [ ] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code). - [ ] Added a relevant changelog entry to the `Unreleased` section in `CHANGELOG.md` - [ ] Re-reviewed `Files changed` in the Github PR explorer - [ ] Review `Codecov Report` in the comment section below once CI passes
2021-06-25 03:41:32 -07:00
// ErrAppConfig defines an error occurred if min-gas-prices field in BaseConfig is empty.
ErrAppConfig = Register(RootCodespace, 40, "error in app.toml")
)
// Register returns an error instance that should be used as the base for
// creating error instances during runtime.
//
// Popular root errors are declared in this package, but extensions may want to
// declare custom codes. This function ensures that no error code is used
// twice. Attempt to reuse an error code results in panic.
//
// Use this function only during a program startup phase.
func Register(codespace string, code uint32, description string) *Error {
// TODO - uniqueness is (codespace, code) combo
if e := getUsed(codespace, code); e != nil {
panic(fmt.Sprintf("error with code %d is already registered: %q", code, e.desc))
}
err := New(codespace, code, description)
setUsed(err)
return err
}
// usedCodes is keeping track of used codes to ensure their uniqueness. No two
// error instances should share the same (codespace, code) tuple.
var usedCodes = map[string]*Error{}
func errorID(codespace string, code uint32) string {
return fmt.Sprintf("%s:%d", codespace, code)
}
func getUsed(codespace string, code uint32) *Error {
return usedCodes[errorID(codespace, code)]
}
func setUsed(err *Error) {
usedCodes[errorID(err.codespace, err.code)] = err
}
// ABCIError will resolve an error code/log from an abci result into
// an error message. If the code is registered, it will map it back to
// the canonical error, so we can do eg. ErrNotFound.Is(err) on something
// we get back from an external API.
//
// This should *only* be used in clients, not in the server side.
// The server (abci app / blockchain) should only refer to registered errors
func ABCIError(codespace string, code uint32, log string) error {
if e := getUsed(codespace, code); e != nil {
return Wrap(e, log)
}
// This is a unique error, will never match on .Is()
// Use Wrap here to get a stack trace
return Wrap(New(codespace, code, "unknown"), log)
}
// Error represents a root error.
//
// Weave framework is using root error to categorize issues. Each instance
// created during the runtime should wrap one of the declared root errors. This
// allows error tests and returning all errors to the client in a safe manner.
//
// All popular root errors are declared in this package. If an extension has to
// declare a custom root error, always use Register function to ensure
// error code uniqueness.
type Error struct {
codespace string
code uint32
desc string
}
func New(codespace string, code uint32, desc string) *Error {
return &Error{codespace: codespace, code: code, desc: desc}
}
func (e Error) Error() string {
return e.desc
}
func (e Error) ABCICode() uint32 {
return e.code
}
func (e Error) Codespace() string {
return e.codespace
}
// Is check if given error instance is of a given kind/type. This involves
// unwrapping given error using the Cause method if available.
func (e *Error) Is(err error) bool {
// Reflect usage is necessary to correctly compare with
// a nil implementation of an error.
if e == nil {
return isNilErr(err)
}
for {
if err == e {
return true
}
// If this is a collection of errors, this function must return
// true if at least one from the group match.
if u, ok := err.(unpacker); ok {
for _, er := range u.Unpack() {
if e.Is(er) {
return true
}
}
}
if c, ok := err.(causer); ok {
err = c.Cause()
} else {
return false
}
}
}
// Wrap extends this error with an additional information.
// It's a handy function to call Wrap with sdk errors.
func (e Error) Wrap(desc string) error { return Wrap(e, desc) }
// Wrapf extends this error with an additional information.
// It's a handy function to call Wrapf with sdk errors.
func (e Error) Wrapf(desc string, args ...interface{}) error { return Wrapf(e, desc, args...) }
func isNilErr(err error) bool {
// Reflect usage is necessary to correctly compare with
// a nil implementation of an error.
if err == nil {
return true
}
if reflect.ValueOf(err).Kind() == reflect.Struct {
return false
}
return reflect.ValueOf(err).IsNil()
}
// Wrap extends given error with an additional information.
//
// If the wrapped error does not provide ABCICode method (ie. stdlib errors),
// it will be labeled as internal error.
//
// If err is nil, this returns nil, avoiding the need for an if statement when
// wrapping a error returned at the end of a function
func Wrap(err error, description string) error {
if err == nil {
return nil
}
// If this error does not carry the stacktrace information yet, attach
// one. This should be done only once per error at the lowest frame
// possible (most inner wrap).
if stackTrace(err) == nil {
err = errors.WithStack(err)
}
return &wrappedError{
parent: err,
msg: description,
}
}
// Wrapf extends given error with an additional information.
//
// This function works like Wrap function with additional functionality of
// formatting the input as specified.
func Wrapf(err error, format string, args ...interface{}) error {
desc := fmt.Sprintf(format, args...)
return Wrap(err, desc)
}
type wrappedError struct {
// This error layer description.
msg string
// The underlying error that triggered this one.
parent error
}
func (e *wrappedError) Error() string {
return fmt.Sprintf("%s: %s", e.msg, e.parent.Error())
}
func (e *wrappedError) Cause() error {
return e.parent
}
// Is reports whether any error in e's chain matches a target.
func (e *wrappedError) Is(target error) bool {
if e == target {
return true
}
w := e.Cause()
for {
if w == target {
return true
}
x, ok := w.(causer)
if ok {
w = x.Cause()
}
if x == nil {
return false
}
}
}
// Unwrap implements the built-in errors.Unwrap
func (e *wrappedError) Unwrap() error {
return e.parent
}
// Recover captures a panic and stop its propagation. If panic happens it is
// transformed into a ErrPanic instance and assigned to given error. Call this
// function using defer in order to work as expected.
func Recover(err *error) {
if r := recover(); r != nil {
*err = Wrapf(ErrPanic, "%v", r)
}
}
// WithType is a helper to augment an error with a corresponding type message
func WithType(err error, obj interface{}) error {
return Wrap(err, fmt.Sprintf("%T", obj))
}
Remove bech32 PubKey support (#7477) * Move PubKey bech32 to legacy package and migrate the usage where possible * update /server * wip * move proto json encoding helper functions to internal * update internal/marshal * wip * update sections which needs legacybech32 * update validators output * fix conflicts * slashing update * add more tests and helper function for ANY JSON serialization * update slashing * Update function documentation * Rename code any-marshal helper functions * Update pubkey unpacking test * Update test comments * solve TestDecodeStore * solve legacytx issues * all code compiles * keyring tests * keyring cleanup * remove AssertMsg * fix some tests * fix add_ledger_test.go * update cli tests * debug cli test * rename clashed bech32 names * linter fixes * update tmservice tests * linter: update legacy deprecated checks * fix names * linting * legacybech32 pubkey type rename * fix staking client * fix test compilation * fix TestGetCmdQuerySigningInfo * rename NewIfcJSONAnyMarshaler * keyring: remove duplicated information from multinfo structure * todo cleanups * Update Changelog * remove some legacybech32 from tests * remove todos * remove printlnJSON from /server CLI and amino encoding * remove protocdc.MarshalJSON * client/show remove duplicated function * remove protocdc package * comment update * remove legacybech32.MustMarshalPubKey from a test * add todo * fix TestPublicKeyUnsafe test * review update * fix bech32 UnmarshalPubKey * Use codec.MarshalIfcJSON * fix linter issues * merging conflict: fix codec.Unmarshal calls * cleanups * Update CHANGELOG.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Reword changelog updates * use pubkey.String for comparison in Test_runAddCmdLedgerWithCustomCoinType * Update GetCmdQuerySigningInfo example * cli: update keys add docs * Add errors AsOf and errors.ErrIO type * restore multisigPubKeyInfo structure bring it back to multiInfo struct * Update codec/proto_codec.go Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com> * Update crypto/keys/ed25519/ed25519_test.go Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com> * Update codec/proto_codec.go Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com> * move pubkey any marshaling tests * Apply suggestions from code review Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com> * review updates * adding missing return * errors: use IsOf instead of AsOf * keyring: add a correct check for key not found in keyring.Get * add checkKeyNotFound * fix linter issues * fix: keyring key not found check * fix keyring tests * fix linting issues * cli tests * fix: 'simd keys show <key> -p' * fix: TestVerifyMultisignature * rename keyring Bech32... functions to Mk... * fix RunAddCmd * Update pubkey display * wip * add more tests * udate keyring output tests * remove todo from ledger tests * rename MkKeyOutput * Changelog update * solve liner issues * add link to github issue Co-authored-by: Aaron Craelius <aaron@regen.network> Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com>
2021-03-25 07:53:22 -07:00
// IsOf checks if a received error is caused by one of the target errors.
// It extends the errors.Is functionality to a list of errors.
func IsOf(received error, targets ...error) bool {
for _, t := range targets {
if errors.Is(received, t) {
return true
}
}
return false
}
// causer is an interface implemented by an error that supports wrapping. Use
// it to test if an error wraps another error instance.
type causer interface {
Cause() error
}
type unpacker interface {
Unpack() []error
}