1 // Copyright (c) 2014 The btcsuite developers
2 // Use of this source code is governed by an ISC
3 // license that can be found in the LICENSE file.
11 // ErrorCode identifies a kind of error. These error codes are NOT used for
12 // JSON-RPC response errors.
15 // These constants are used to identify a specific RuleError.
17 // ErrDuplicateMethod indicates a command with the specified method
19 ErrDuplicateMethod ErrorCode = iota
21 // ErrInvalidUsageFlags indicates one or more unrecognized flag bits
25 // ErrInvalidType indicates a type was passed that is not the required
29 // ErrEmbeddedType indicates the provided command struct contains an
30 // embedded type which is not not supported.
33 // ErrUnexportedField indiciates the provided command struct contains an
34 // unexported field which is not supported.
37 // ErrUnsupportedFieldType indicates the type of a field in the provided
38 // command struct is not one of the supported types.
39 ErrUnsupportedFieldType
41 // ErrNonOptionalField indicates a non-optional field was specified
42 // after an optional field.
45 // ErrNonOptionalDefault indicates a 'jsonrpcdefault' struct tag was
46 // specified for a non-optional field.
49 // ErrMismatchedDefault indicates a 'jsonrpcdefault' struct tag contains
50 // a value that doesn't match the type of the field.
53 // ErrUnregisteredMethod indicates a method was specified that has not
57 // ErrMissingDescription indicates a description required to generate
61 // ErrNumParams inidcates the number of params supplied do not
62 // match the requirements of the associated command.
65 // numErrorCodes is the maximum error code number used in tests.
69 // Map of ErrorCode values back to their constant names for pretty printing.
70 var errorCodeStrings = map[ErrorCode]string{
71 ErrDuplicateMethod: "ErrDuplicateMethod",
72 ErrInvalidUsageFlags: "ErrInvalidUsageFlags",
73 ErrInvalidType: "ErrInvalidType",
74 ErrEmbeddedType: "ErrEmbeddedType",
75 ErrUnexportedField: "ErrUnexportedField",
76 ErrUnsupportedFieldType: "ErrUnsupportedFieldType",
77 ErrNonOptionalField: "ErrNonOptionalField",
78 ErrNonOptionalDefault: "ErrNonOptionalDefault",
79 ErrMismatchedDefault: "ErrMismatchedDefault",
80 ErrUnregisteredMethod: "ErrUnregisteredMethod",
81 ErrMissingDescription: "ErrMissingDescription",
82 ErrNumParams: "ErrNumParams",
85 // String returns the ErrorCode as a human-readable name.
86 func (e ErrorCode) String() string {
87 if s := errorCodeStrings[e]; s != "" {
90 return fmt.Sprintf("Unknown ErrorCode (%d)", int(e))
93 // Error identifies a general error. This differs from an RPCError in that this
94 // error typically is used more by the consumers of the package as opposed to
95 // RPCErrors which are intended to be returned to the client across the wire via
96 // a JSON-RPC Response. The caller can use type assertions to determine the
97 // specific error and access the ErrorCode field.
99 ErrorCode ErrorCode // Describes the kind of error
100 Description string // Human readable description of the issue
103 // Error satisfies the error interface and prints human-readable errors.
104 func (e Error) Error() string {
108 // makeError creates an Error given a set of arguments.
109 func makeError(c ErrorCode, desc string) Error {
110 return Error{ErrorCode: c, Description: desc}