tendermint/lite/errors/errors.go

112 lines
2.3 KiB
Go
Raw Normal View History

2017-10-24 12:34:36 +02:00
package errors
import (
"fmt"
2018-07-02 14:58:07 -04:00
cmn "github.com/tendermint/tendermint/libs/common"
2017-10-24 12:34:36 +02:00
)
//----------------------------------------
// Error types
type errCommitNotFound struct{}
2017-10-24 12:34:36 +02:00
func (e errCommitNotFound) Error() string {
return "Commit not found by provider"
2017-10-24 12:34:36 +02:00
}
type errUnexpectedValidators struct {
got []byte
want []byte
2017-10-24 12:34:36 +02:00
}
func (e errUnexpectedValidators) Error() string {
return fmt.Sprintf("Validator set is different. Got %X want %X",
e.got, e.want)
2017-10-24 12:34:36 +02:00
}
type errUnknownValidators struct {
chainID string
height int64
2017-10-24 12:34:36 +02:00
}
func (e errUnknownValidators) Error() string {
return fmt.Sprintf("Validators are unknown or missing for chain %s and height %d",
e.chainID, e.height)
2017-10-24 12:34:36 +02:00
}
type errEmptyTree struct{}
func (e errEmptyTree) Error() string {
return "Tree is empty"
}
//----------------------------------------
// Methods for above error types
//-----------------
// ErrCommitNotFound
// ErrCommitNotFound indicates that a the requested commit was not found.
func ErrCommitNotFound() error {
return cmn.ErrorWrap(errCommitNotFound{}, "")
2017-10-24 12:34:36 +02:00
}
func IsErrCommitNotFound(err error) bool {
if err_, ok := err.(cmn.Error); ok {
_, ok := err_.Data().(errCommitNotFound)
return ok
}
return false
2017-10-24 12:34:36 +02:00
}
//-----------------
// ErrUnexpectedValidators
// ErrUnexpectedValidators indicates a validator set mismatch.
func ErrUnexpectedValidators(got, want []byte) error {
return cmn.ErrorWrap(errUnexpectedValidators{
got: got,
want: want,
}, "")
2017-10-24 12:34:36 +02:00
}
func IsErrUnexpectedValidators(err error) bool {
if err_, ok := err.(cmn.Error); ok {
_, ok := err_.Data().(errUnexpectedValidators)
return ok
}
return false
2017-10-24 12:34:36 +02:00
}
//-----------------
// ErrUnknownValidators
// ErrUnknownValidators indicates that some validator set was missing or unknown.
func ErrUnknownValidators(chainID string, height int64) error {
return cmn.ErrorWrap(errUnknownValidators{chainID, height}, "")
2017-10-24 12:34:36 +02:00
}
func IsErrUnknownValidators(err error) bool {
if err_, ok := err.(cmn.Error); ok {
_, ok := err_.Data().(errUnknownValidators)
return ok
}
return false
2017-10-24 12:34:36 +02:00
}
//-----------------
// ErrEmptyTree
func ErrEmptyTree() error {
return cmn.ErrorWrap(errEmptyTree{}, "")
}
func IsErrEmptyTree(err error) bool {
if err_, ok := err.(cmn.Error); ok {
_, ok := err_.Data().(errEmptyTree)
return ok
}
return false
}