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.

99 lines
2.0 KiB

  1. package errors
  2. import (
  3. "fmt"
  4. "github.com/pkg/errors"
  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 errors.Wrap(errCommitNotFound{}, "")
  39. }
  40. func IsErrCommitNotFound(err error) bool {
  41. _, ok := errors.Cause(err).(errCommitNotFound)
  42. return ok
  43. }
  44. //-----------------
  45. // ErrUnexpectedValidators
  46. // ErrUnexpectedValidators indicates a validator set mismatch.
  47. func ErrUnexpectedValidators(got, want []byte) error {
  48. return errors.Wrap(errUnexpectedValidators{
  49. got: got,
  50. want: want,
  51. }, "")
  52. }
  53. func IsErrUnexpectedValidators(err error) bool {
  54. _, ok := errors.Cause(err).(errUnexpectedValidators)
  55. return ok
  56. }
  57. //-----------------
  58. // ErrUnknownValidators
  59. // ErrUnknownValidators indicates that some validator set was missing or unknown.
  60. func ErrUnknownValidators(chainID string, height int64) error {
  61. return errors.Wrap(errUnknownValidators{chainID, height}, "")
  62. }
  63. func IsErrUnknownValidators(err error) bool {
  64. _, ok := errors.Cause(err).(errUnknownValidators)
  65. return ok
  66. }
  67. //-----------------
  68. // ErrEmptyTree
  69. func ErrEmptyTree() error {
  70. return errors.Wrap(errEmptyTree{}, "")
  71. }
  72. func IsErrEmptyTree(err error) bool {
  73. _, ok := errors.Cause(err).(errEmptyTree)
  74. return ok
  75. }