errors.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
  2. // SPDX-License-Identifier: MIT
  3. // Package rtcerr implements the error wrappers defined throughout the
  4. // WebRTC 1.0 specifications.
  5. package rtcerr
  6. import (
  7. "fmt"
  8. )
  9. // UnknownError indicates the operation failed for an unknown transient reason.
  10. type UnknownError struct {
  11. Err error
  12. }
  13. func (e *UnknownError) Error() string {
  14. return fmt.Sprintf("UnknownError: %v", e.Err)
  15. }
  16. // Unwrap returns the result of calling the Unwrap method on err, if err's type contains
  17. // an Unwrap method returning error. Otherwise, Unwrap returns nil.
  18. func (e *UnknownError) Unwrap() error {
  19. return e.Err
  20. }
  21. // InvalidStateError indicates the object is in an invalid state.
  22. type InvalidStateError struct {
  23. Err error
  24. }
  25. func (e *InvalidStateError) Error() string {
  26. return fmt.Sprintf("InvalidStateError: %v", e.Err)
  27. }
  28. // Unwrap returns the result of calling the Unwrap method on err, if err's type contains
  29. // an Unwrap method returning error. Otherwise, Unwrap returns nil.
  30. func (e *InvalidStateError) Unwrap() error {
  31. return e.Err
  32. }
  33. // InvalidAccessError indicates the object does not support the operation or
  34. // argument.
  35. type InvalidAccessError struct {
  36. Err error
  37. }
  38. func (e *InvalidAccessError) Error() string {
  39. return fmt.Sprintf("InvalidAccessError: %v", e.Err)
  40. }
  41. // Unwrap returns the result of calling the Unwrap method on err, if err's type contains
  42. // an Unwrap method returning error. Otherwise, Unwrap returns nil.
  43. func (e *InvalidAccessError) Unwrap() error {
  44. return e.Err
  45. }
  46. // NotSupportedError indicates the operation is not supported.
  47. type NotSupportedError struct {
  48. Err error
  49. }
  50. func (e *NotSupportedError) Error() string {
  51. return fmt.Sprintf("NotSupportedError: %v", e.Err)
  52. }
  53. // Unwrap returns the result of calling the Unwrap method on err, if err's type contains
  54. // an Unwrap method returning error. Otherwise, Unwrap returns nil.
  55. func (e *NotSupportedError) Unwrap() error {
  56. return e.Err
  57. }
  58. // InvalidModificationError indicates the object cannot be modified in this way.
  59. type InvalidModificationError struct {
  60. Err error
  61. }
  62. func (e *InvalidModificationError) Error() string {
  63. return fmt.Sprintf("InvalidModificationError: %v", e.Err)
  64. }
  65. // Unwrap returns the result of calling the Unwrap method on err, if err's type contains
  66. // an Unwrap method returning error. Otherwise, Unwrap returns nil.
  67. func (e *InvalidModificationError) Unwrap() error {
  68. return e.Err
  69. }
  70. // SyntaxError indicates the string did not match the expected pattern.
  71. type SyntaxError struct {
  72. Err error
  73. }
  74. func (e *SyntaxError) Error() string {
  75. return fmt.Sprintf("SyntaxError: %v", e.Err)
  76. }
  77. // Unwrap returns the result of calling the Unwrap method on err, if err's type contains
  78. // an Unwrap method returning error. Otherwise, Unwrap returns nil.
  79. func (e *SyntaxError) Unwrap() error {
  80. return e.Err
  81. }
  82. // TypeError indicates an error when a value is not of the expected type.
  83. type TypeError struct {
  84. Err error
  85. }
  86. func (e *TypeError) Error() string {
  87. return fmt.Sprintf("TypeError: %v", e.Err)
  88. }
  89. // Unwrap returns the result of calling the Unwrap method on err, if err's type contains
  90. // an Unwrap method returning error. Otherwise, Unwrap returns nil.
  91. func (e *TypeError) Unwrap() error {
  92. return e.Err
  93. }
  94. // OperationError indicates the operation failed for an operation-specific
  95. // reason.
  96. type OperationError struct {
  97. Err error
  98. }
  99. func (e *OperationError) Error() string {
  100. return fmt.Sprintf("OperationError: %v", e.Err)
  101. }
  102. // Unwrap returns the result of calling the Unwrap method on err, if err's type contains
  103. // an Unwrap method returning error. Otherwise, Unwrap returns nil.
  104. func (e *OperationError) Unwrap() error {
  105. return e.Err
  106. }
  107. // NotReadableError indicates the input/output read operation failed.
  108. type NotReadableError struct {
  109. Err error
  110. }
  111. func (e *NotReadableError) Error() string {
  112. return fmt.Sprintf("NotReadableError: %v", e.Err)
  113. }
  114. // Unwrap returns the result of calling the Unwrap method on err, if err's type contains
  115. // an Unwrap method returning error. Otherwise, Unwrap returns nil.
  116. func (e *NotReadableError) Unwrap() error {
  117. return e.Err
  118. }
  119. // RangeError indicates an error when a value is not in the set or range
  120. // of allowed values.
  121. type RangeError struct {
  122. Err error
  123. }
  124. func (e *RangeError) Error() string {
  125. return fmt.Sprintf("RangeError: %v", e.Err)
  126. }
  127. // Unwrap returns the result of calling the Unwrap method on err, if err's type contains
  128. // an Unwrap method returning error. Otherwise, Unwrap returns nil.
  129. func (e *RangeError) Unwrap() error {
  130. return e.Err
  131. }