github.com/okex/exchain@v1.8.0/libs/tendermint/lite/errors/errors.go (about)

     1  package errors
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/pkg/errors"
     7  )
     8  
     9  //----------------------------------------
    10  // Error types
    11  
    12  type errCommitNotFound struct{}
    13  
    14  func (e errCommitNotFound) Error() string {
    15  	return "Commit not found by provider"
    16  }
    17  
    18  type errUnexpectedValidators struct {
    19  	got  []byte
    20  	want []byte
    21  }
    22  
    23  func (e errUnexpectedValidators) Error() string {
    24  	return fmt.Sprintf("Validator set is different. Got %X want %X",
    25  		e.got, e.want)
    26  }
    27  
    28  type errUnknownValidators struct {
    29  	chainID string
    30  	height  int64
    31  }
    32  
    33  func (e errUnknownValidators) Error() string {
    34  	return fmt.Sprintf("Validators are unknown or missing for chain %s and height %d",
    35  		e.chainID, e.height)
    36  }
    37  
    38  type errEmptyTree struct{}
    39  
    40  func (e errEmptyTree) Error() string {
    41  	return "Tree is empty"
    42  }
    43  
    44  //----------------------------------------
    45  // Methods for above error types
    46  
    47  //-----------------
    48  // ErrCommitNotFound
    49  
    50  // ErrCommitNotFound indicates that a the requested commit was not found.
    51  func ErrCommitNotFound() error {
    52  	return errors.Wrap(errCommitNotFound{}, "")
    53  }
    54  
    55  func IsErrCommitNotFound(err error) bool {
    56  	_, ok := errors.Cause(err).(errCommitNotFound)
    57  	return ok
    58  }
    59  
    60  //-----------------
    61  // ErrUnexpectedValidators
    62  
    63  // ErrUnexpectedValidators indicates a validator set mismatch.
    64  func ErrUnexpectedValidators(got, want []byte) error {
    65  	return errors.Wrap(errUnexpectedValidators{
    66  		got:  got,
    67  		want: want,
    68  	}, "")
    69  }
    70  
    71  func IsErrUnexpectedValidators(err error) bool {
    72  	_, ok := errors.Cause(err).(errUnexpectedValidators)
    73  	return ok
    74  }
    75  
    76  //-----------------
    77  // ErrUnknownValidators
    78  
    79  // ErrUnknownValidators indicates that some validator set was missing or unknown.
    80  func ErrUnknownValidators(chainID string, height int64) error {
    81  	return errors.Wrap(errUnknownValidators{chainID, height}, "")
    82  }
    83  
    84  func IsErrUnknownValidators(err error) bool {
    85  	_, ok := errors.Cause(err).(errUnknownValidators)
    86  	return ok
    87  }
    88  
    89  //-----------------
    90  // ErrEmptyTree
    91  
    92  func ErrEmptyTree() error {
    93  	return errors.Wrap(errEmptyTree{}, "")
    94  }
    95  
    96  func IsErrEmptyTree(err error) bool {
    97  	_, ok := errors.Cause(err).(errEmptyTree)
    98  	return ok
    99  }