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.

133 lines
2.8 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. type errEmptyTree struct{}
  33. func (e errEmptyTree) Error() string {
  34. return "Tree is empty"
  35. }
  36. //----------------------------------------
  37. // Methods for above error types
  38. //-----------------
  39. // ErrCommitNotFound
  40. // ErrCommitNotFound indicates that a the requested commit was not found.
  41. func ErrCommitNotFound() error {
  42. return cmn.ErrorWrap(errCommitNotFound{}, "")
  43. }
  44. func IsErrCommitNotFound(err error) bool {
  45. if err_, ok := err.(cmn.Error); ok {
  46. _, ok := err_.Data().(errCommitNotFound)
  47. return ok
  48. }
  49. return false
  50. }
  51. //-----------------
  52. // ErrUnexpectedValidators
  53. // ErrUnexpectedValidators indicates a validator set mismatch.
  54. func ErrUnexpectedValidators(got, want []byte) error {
  55. return cmn.ErrorWrap(errUnexpectedValidators{
  56. got: got,
  57. want: want,
  58. }, "")
  59. }
  60. func IsErrUnexpectedValidators(err error) bool {
  61. if err_, ok := err.(cmn.Error); ok {
  62. _, ok := err_.Data().(errUnexpectedValidators)
  63. return ok
  64. }
  65. return false
  66. }
  67. //-----------------
  68. // ErrTooMuchChange
  69. // ErrTooMuchChange indicates that the underlying validator set was changed by >1/3.
  70. func ErrTooMuchChange() error {
  71. return cmn.ErrorWrap(errTooMuchChange{}, "")
  72. }
  73. func IsErrTooMuchChange(err error) bool {
  74. if err_, ok := err.(cmn.Error); ok {
  75. _, ok := err_.Data().(errTooMuchChange)
  76. return ok
  77. }
  78. return false
  79. }
  80. //-----------------
  81. // ErrUnknownValidators
  82. // ErrUnknownValidators indicates that some validator set was missing or unknown.
  83. func ErrUnknownValidators(chainID string, height int64) error {
  84. return cmn.ErrorWrap(errUnknownValidators{chainID, height}, "")
  85. }
  86. func IsErrUnknownValidators(err error) bool {
  87. if err_, ok := err.(cmn.Error); ok {
  88. _, ok := err_.Data().(errUnknownValidators)
  89. return ok
  90. }
  91. return false
  92. }
  93. //-----------------
  94. // ErrEmptyTree
  95. func ErrEmptyTree() error {
  96. return cmn.ErrorWrap(errEmptyTree{}, "")
  97. }
  98. func IsErrEmptyTree(err error) bool {
  99. if err_, ok := err.(cmn.Error); ok {
  100. _, ok := err_.Data().(errEmptyTree)
  101. return ok
  102. }
  103. return false
  104. }