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.

86 lines
2.3 KiB

  1. package errors
  2. import (
  3. "fmt"
  4. "github.com/pkg/errors"
  5. )
  6. var (
  7. errValidatorsChanged = fmt.Errorf("Validators differ between header and certifier")
  8. errCommitNotFound = fmt.Errorf("Commit not found by provider")
  9. errTooMuchChange = fmt.Errorf("Validators change too much to safely update")
  10. errPastTime = fmt.Errorf("Update older than certifier height")
  11. errNoPathFound = fmt.Errorf("Cannot find a path of validators")
  12. )
  13. // IsCommitNotFoundErr checks whether an error is due to missing data
  14. func IsCommitNotFoundErr(err error) bool {
  15. return err != nil && (errors.Cause(err) == errCommitNotFound)
  16. }
  17. func ErrCommitNotFound() error {
  18. return errors.WithStack(errCommitNotFound)
  19. }
  20. // IsValidatorsChangedErr checks whether an error is due
  21. // to a differing validator set
  22. func IsValidatorsChangedErr(err error) bool {
  23. return err != nil && (errors.Cause(err) == errValidatorsChanged)
  24. }
  25. func ErrValidatorsChanged() error {
  26. return errors.WithStack(errValidatorsChanged)
  27. }
  28. // IsTooMuchChangeErr checks whether an error is due to too much change
  29. // between these validators sets
  30. func IsTooMuchChangeErr(err error) bool {
  31. return err != nil && (errors.Cause(err) == errTooMuchChange)
  32. }
  33. func ErrTooMuchChange() error {
  34. return errors.WithStack(errTooMuchChange)
  35. }
  36. func IsPastTimeErr(err error) bool {
  37. return err != nil && (errors.Cause(err) == errPastTime)
  38. }
  39. func ErrPastTime() error {
  40. return errors.WithStack(errPastTime)
  41. }
  42. // IsNoPathFoundErr checks whether an error is due to no path of
  43. // validators in provider from where we are to where we want to be
  44. func IsNoPathFoundErr(err error) bool {
  45. return err != nil && (errors.Cause(err) == errNoPathFound)
  46. }
  47. func ErrNoPathFound() error {
  48. return errors.WithStack(errNoPathFound)
  49. }
  50. //--------------------------------------------
  51. type errHeightMismatch struct {
  52. h1, h2 int
  53. }
  54. func (e errHeightMismatch) Error() string {
  55. return fmt.Sprintf("Blocks don't match - %d vs %d", e.h1, e.h2)
  56. }
  57. // IsHeightMismatchErr checks whether an error is due to data from different blocks
  58. func IsHeightMismatchErr(err error) bool {
  59. if err == nil {
  60. return false
  61. }
  62. _, ok := errors.Cause(err).(errHeightMismatch)
  63. return ok
  64. }
  65. // ErrHeightMismatch returns an mismatch error with stack-trace
  66. func ErrHeightMismatch(h1, h2 int) error {
  67. return errors.WithStack(errHeightMismatch{h1, h2})
  68. }