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.

111 lines
2.3 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 errUnknownValidators struct {
  21. chainID string
  22. height int64
  23. }
  24. func (e errUnknownValidators) Error() string {
  25. return fmt.Sprintf("Validators are unknown or missing for chain %s and height %d",
  26. e.chainID, e.height)
  27. }
  28. type errEmptyTree struct{}
  29. func (e errEmptyTree) Error() string {
  30. return "Tree is empty"
  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. // ErrUnknownValidators
  65. // ErrUnknownValidators indicates that some validator set was missing or unknown.
  66. func ErrUnknownValidators(chainID string, height int64) error {
  67. return cmn.ErrorWrap(errUnknownValidators{chainID, height}, "")
  68. }
  69. func IsErrUnknownValidators(err error) bool {
  70. if err_, ok := err.(cmn.Error); ok {
  71. _, ok := err_.Data().(errUnknownValidators)
  72. return ok
  73. }
  74. return false
  75. }
  76. //-----------------
  77. // ErrEmptyTree
  78. func ErrEmptyTree() error {
  79. return cmn.ErrorWrap(errEmptyTree{}, "")
  80. }
  81. func IsErrEmptyTree(err error) bool {
  82. if err_, ok := err.(cmn.Error); ok {
  83. _, ok := err_.Data().(errEmptyTree)
  84. return ok
  85. }
  86. return false
  87. }