errors.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package client
  2. import (
  3. "errors"
  4. "fmt"
  5. )
  6. var (
  7. ErrNoRootKeys = errors.New("tuf: no root keys found in local meta store")
  8. ErrInsufficientKeys = errors.New("tuf: insufficient keys to meet threshold")
  9. ErrNoLocalSnapshot = errors.New("tuf: no snapshot stored locally")
  10. )
  11. type ErrMissingRemoteMetadata struct {
  12. Name string
  13. }
  14. func (e ErrMissingRemoteMetadata) Error() string {
  15. return fmt.Sprintf("tuf: missing remote metadata %s", e.Name)
  16. }
  17. type ErrDownloadFailed struct {
  18. File string
  19. Err error
  20. }
  21. func (e ErrDownloadFailed) Error() string {
  22. return fmt.Sprintf("tuf: failed to download %s: %s", e.File, e.Err)
  23. }
  24. type ErrDecodeFailed struct {
  25. File string
  26. Err error
  27. }
  28. func (e ErrDecodeFailed) Error() string {
  29. return fmt.Sprintf("tuf: failed to decode %s: %s", e.File, e.Err)
  30. }
  31. type ErrMaxDelegations struct {
  32. Target string
  33. MaxDelegations int
  34. SnapshotVersion int64
  35. }
  36. func (e ErrMaxDelegations) Error() string {
  37. return fmt.Sprintf("tuf: max delegation of %d reached searching for %s with snapshot version %d", e.MaxDelegations, e.Target, e.SnapshotVersion)
  38. }
  39. type ErrNotFound struct {
  40. File string
  41. }
  42. func (e ErrNotFound) Error() string {
  43. return fmt.Sprintf("tuf: file not found: %s", e.File)
  44. }
  45. func IsNotFound(err error) bool {
  46. _, ok := err.(ErrNotFound)
  47. return ok
  48. }
  49. type ErrWrongSize struct {
  50. File string
  51. Actual int64
  52. Expected int64
  53. }
  54. func (e ErrWrongSize) Error() string {
  55. return fmt.Sprintf("tuf: unexpected file size: %s (expected %d bytes, got %d bytes)", e.File, e.Expected, e.Actual)
  56. }
  57. type ErrUnknownTarget struct {
  58. Name string
  59. SnapshotVersion int64
  60. }
  61. func (e ErrUnknownTarget) Error() string {
  62. return fmt.Sprintf("tuf: unknown target file: %s with snapshot version %d", e.Name, e.SnapshotVersion)
  63. }
  64. type ErrMetaTooLarge struct {
  65. Name string
  66. Size int64
  67. MaxSize int64
  68. }
  69. func (e ErrMetaTooLarge) Error() string {
  70. return fmt.Sprintf("tuf: %s size %d bytes greater than maximum %d bytes", e.Name, e.Size, e.MaxSize)
  71. }
  72. type ErrInvalidURL struct {
  73. URL string
  74. }
  75. func (e ErrInvalidURL) Error() string {
  76. return fmt.Sprintf("tuf: invalid repository URL %s", e.URL)
  77. }
  78. type ErrRoleNotInSnapshot struct {
  79. Role string
  80. SnapshotVersion int64
  81. }
  82. func (e ErrRoleNotInSnapshot) Error() string {
  83. return fmt.Sprintf("tuf: role %s not in snapshot version %d", e.Role, e.SnapshotVersion)
  84. }