github.com/jeffallen/go-ethereum@v1.1.4-0.20150910155051-571d3236c49c/rpc/shared/errors.go (about)

     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  
    17  package shared
    18  
    19  import "fmt"
    20  
    21  type InvalidTypeError struct {
    22  	method string
    23  	msg    string
    24  }
    25  
    26  func (e *InvalidTypeError) Error() string {
    27  	return fmt.Sprintf("invalid type on field %s: %s", e.method, e.msg)
    28  }
    29  
    30  func NewInvalidTypeError(method, msg string) *InvalidTypeError {
    31  	return &InvalidTypeError{
    32  		method: method,
    33  		msg:    msg,
    34  	}
    35  }
    36  
    37  type InsufficientParamsError struct {
    38  	have int
    39  	want int
    40  }
    41  
    42  func (e *InsufficientParamsError) Error() string {
    43  	return fmt.Sprintf("insufficient params, want %d have %d", e.want, e.have)
    44  }
    45  
    46  func NewInsufficientParamsError(have int, want int) *InsufficientParamsError {
    47  	return &InsufficientParamsError{
    48  		have: have,
    49  		want: want,
    50  	}
    51  }
    52  
    53  type NotImplementedError struct {
    54  	Method string
    55  }
    56  
    57  func (e *NotImplementedError) Error() string {
    58  	return fmt.Sprintf("%s method not implemented", e.Method)
    59  }
    60  
    61  func NewNotImplementedError(method string) *NotImplementedError {
    62  	return &NotImplementedError{
    63  		Method: method,
    64  	}
    65  }
    66  
    67  type DecodeParamError struct {
    68  	err string
    69  }
    70  
    71  func (e *DecodeParamError) Error() string {
    72  	return fmt.Sprintf("could not decode, %s", e.err)
    73  
    74  }
    75  
    76  func NewDecodeParamError(errstr string) error {
    77  	return &DecodeParamError{
    78  		err: errstr,
    79  	}
    80  }
    81  
    82  type ValidationError struct {
    83  	ParamName string
    84  	msg       string
    85  }
    86  
    87  func (e *ValidationError) Error() string {
    88  	return fmt.Sprintf("%s not valid, %s", e.ParamName, e.msg)
    89  }
    90  
    91  func NewValidationError(param string, msg string) error {
    92  	return &ValidationError{
    93  		ParamName: param,
    94  		msg:       msg,
    95  	}
    96  }
    97  
    98  type NotAvailableError struct {
    99  	Method string
   100  	Reason string
   101  }
   102  
   103  func (e *NotAvailableError) Error() string {
   104  	return fmt.Sprintf("%s method not available: %s", e.Method, e.Reason)
   105  }
   106  
   107  func NewNotAvailableError(method string, reason string) *NotAvailableError {
   108  	return &NotAvailableError{
   109  		Method: method,
   110  		Reason: reason,
   111  	}
   112  }