errors.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (c)2019 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2023-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by version 2.0 of the Apache License.
  11. */
  12. /****/
  13. package ztnode
  14. /*
  15. // errTypeName returns the type name of an error minus any leading * character.
  16. func errTypeName(err error) string {
  17. if err == nil {
  18. return ""
  19. }
  20. et := reflect.TypeOf(err)
  21. if et.Kind() == reflect.Ptr {
  22. return et.Elem().Name()
  23. }
  24. return et.Name()
  25. }
  26. //////////////////////////////////////////////////////////////////////////////
  27. // Err indicates a general LF error such as an invalid parameter or state.
  28. type Err string
  29. func (e Err) Error() string { return (string)(e) }
  30. // General errors
  31. const (
  32. ErrInvalidPublicKey Err = "invalid public key"
  33. ErrInvalidPrivateKey Err = "invalid private key"
  34. ErrInvalidParameter Err = "invalid parameter"
  35. ErrInvalidObject Err = "invalid object"
  36. ErrUnsupportedType Err = "unsupported type"
  37. ErrUnsupportedCurve Err = "unsupported ECC curve (for this purpose)"
  38. ErrOutOfRange Err = "parameter out of range"
  39. ErrWharrgarblFailed Err = "Wharrgarbl proof of work algorithm failed (out of memory?)"
  40. ErrIO Err = "I/O error"
  41. ErrIncorrectKey Err = "incorrect key"
  42. ErrAlreadyConnected Err = "already connected"
  43. ErrRecordNotFound Err = "record not found"
  44. ErrRecordIsNewer Err = "record is newer than timestamp"
  45. ErrPulseSpanExeceeded Err = "pulse is more than one year after record"
  46. ErrDuplicateRecord Err = "duplicate record"
  47. ErrPrivateKeyRequired Err = "private key required"
  48. ErrInvalidMessageSize Err = "message size invalid"
  49. ErrQueryRequiresSelectors Err = "query requires at least one selector"
  50. ErrQueryInvalidSortOrder Err = "invalid sort order value"
  51. ErrAlreadyMounted Err = "mount point already mounted"
  52. )
  53. //////////////////////////////////////////////////////////////////////////////
  54. // ErrRecord indicates an error related to an invalid record or a record failing a check.
  55. type ErrRecord string
  56. func (e ErrRecord) Error() string { return (string)(e) }
  57. // Errs indicating that a record is invalid
  58. const (
  59. ErrRecordInvalid ErrRecord = "record invalid"
  60. ErrRecordOwnerSignatureCheckFailed ErrRecord = "owner signature check failed"
  61. ErrRecordInsufficientWork ErrRecord = "insufficient work to pay for this record"
  62. ErrRecordNotApproved ErrRecord = "record not currently approved (via proof of work and/or certificates)"
  63. ErrRecordInsufficientLinks ErrRecord = "insufficient links"
  64. ErrRecordTooManyLinks ErrRecord = "too many links"
  65. ErrRecordInvalidLinks ErrRecord = "links must be sorted and unique"
  66. ErrRecordTooManySelectors ErrRecord = "too many selectors"
  67. ErrRecordUnsupportedAlgorithm ErrRecord = "unsupported algorithm or type"
  68. ErrRecordTooLarge ErrRecord = "record too large"
  69. ErrRecordValueTooLarge ErrRecord = "record value too large"
  70. ErrRecordViolatesSpecialRelativity ErrRecord = "record timestamp too far in the future"
  71. ErrRecordTooOld ErrRecord = "record older than network timestamp floor"
  72. ErrRecordCertificateInvalid ErrRecord = "certificate invalid"
  73. ErrRecordCertificateRequired ErrRecord = "certificate required"
  74. ErrRecordProhibited ErrRecord = "record administratively prohibited"
  75. )
  76. //////////////////////////////////////////////////////////////////////////////
  77. // ErrDatabase contains information about a database related problem.
  78. type ErrDatabase struct {
  79. // ErrCode is the error code returned by the C database module.
  80. ErrCode int
  81. // ErrMessage is an error message supplied by the C code or by Go (optional)
  82. ErrMessage string
  83. }
  84. func (e ErrDatabase) Error() string {
  85. return fmt.Sprintf("database error: %d (%s)", e.ErrCode, e.ErrMessage)
  86. }
  87. //////////////////////////////////////////////////////////////////////////////
  88. // ErrAPI (response) indicates an error and is returned with non-200 responses.
  89. type ErrAPI struct {
  90. Code int `` // HTTP response code
  91. Message string `json:",omitempty"` // Message indicating the reason for the error
  92. ErrTypeName string `json:",omitempty"` // Name of LF native error or empty if HTTP or transport error
  93. }
  94. // Error implements the error interface, making APIError an 'error' in the Go sense.
  95. func (e ErrAPI) Error() string {
  96. if len(e.ErrTypeName) > 0 {
  97. return fmt.Sprintf("%d:%s:%s", e.Code, e.ErrTypeName, e.Message)
  98. }
  99. return fmt.Sprintf("%d:%s", e.Code, e.Message)
  100. }
  101. //////////////////////////////////////////////////////////////////////////////
  102. */