errors.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // Copyright 2015 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package shared
  17. import "fmt"
  18. type InvalidTypeError struct {
  19. method string
  20. msg string
  21. }
  22. func (e *InvalidTypeError) Error() string {
  23. return fmt.Sprintf("invalid type on field %s: %s", e.method, e.msg)
  24. }
  25. func NewInvalidTypeError(method, msg string) *InvalidTypeError {
  26. return &InvalidTypeError{
  27. method: method,
  28. msg: msg,
  29. }
  30. }
  31. type InsufficientParamsError struct {
  32. have int
  33. want int
  34. }
  35. func (e *InsufficientParamsError) Error() string {
  36. return fmt.Sprintf("insufficient params, want %d have %d", e.want, e.have)
  37. }
  38. func NewInsufficientParamsError(have int, want int) *InsufficientParamsError {
  39. return &InsufficientParamsError{
  40. have: have,
  41. want: want,
  42. }
  43. }
  44. type NotImplementedError struct {
  45. Method string
  46. }
  47. func (e *NotImplementedError) Error() string {
  48. return fmt.Sprintf("%s method not implemented", e.Method)
  49. }
  50. func NewNotImplementedError(method string) *NotImplementedError {
  51. return &NotImplementedError{
  52. Method: method,
  53. }
  54. }
  55. type NotReadyError struct {
  56. Resource string
  57. }
  58. func (e *NotReadyError) Error() string {
  59. return fmt.Sprintf("%s not ready", e.Resource)
  60. }
  61. func NewNotReadyError(resource string) *NotReadyError {
  62. return &NotReadyError{
  63. Resource: resource,
  64. }
  65. }
  66. type DecodeParamError struct {
  67. err string
  68. }
  69. func (e *DecodeParamError) Error() string {
  70. return fmt.Sprintf("could not decode, %s", e.err)
  71. }
  72. func NewDecodeParamError(errstr string) error {
  73. return &DecodeParamError{
  74. err: errstr,
  75. }
  76. }
  77. type ValidationError struct {
  78. ParamName string
  79. msg string
  80. }
  81. func (e *ValidationError) Error() string {
  82. return fmt.Sprintf("%s not valid, %s", e.ParamName, e.msg)
  83. }
  84. func NewValidationError(param string, msg string) error {
  85. return &ValidationError{
  86. ParamName: param,
  87. msg: msg,
  88. }
  89. }
  90. type NotAvailableError struct {
  91. Method string
  92. Reason string
  93. }
  94. func (e *NotAvailableError) Error() string {
  95. return fmt.Sprintf("%s method not available: %s", e.Method, e.Reason)
  96. }
  97. func NewNotAvailableError(method string, reason string) *NotAvailableError {
  98. return &NotAvailableError{
  99. Method: method,
  100. Reason: reason,
  101. }
  102. }