You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
2.4 KiB

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