code

package
v0.0.24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2018 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package code defines error code values used by the jrpc2 package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Code

type Code int32

A Code is an error response code, that satisfies the error interface.

The error codes from and including -32768 to -32000 are reserved for pre-defined errors. Any code within this range, but not defined explicitly below is reserved for future use. The remainder of the space is available for application defined errors.

See also: https://www.jsonrpc.org/specification#error_object

const (
	ParseError     Code = -32700 // Invalid JSON received by the server
	InvalidRequest Code = -32600 // The JSON sent is not a valid request object
	MethodNotFound Code = -32601 // The method does not exist or is unavailable
	InvalidParams  Code = -32602 // Invalid method parameters
	InternalError  Code = -32603 // Internal JSON-RPC error
)

Pre-defined error codes, including the standard ones from the JSON-RPC specification and some specific to this implementation.

const (
	NoError          Code = -32099 // Denotes a nil error (used by FromError)
	SystemError      Code = -32098 // Errors from the operating environment
	Cancelled        Code = -32097 // Request cancelled (context.Canceled)
	DeadlineExceeded Code = -32096 // Request deadline exceeded (context.DeadlineExceeded)
)

The JSON-RPC 2.0 specification reserves the range -32000 to -32099 for implementation-defined server errors. These are used by the jrpc2 package.

func FromError added in v0.0.22

func FromError(err error) Code

FromError returns a Code to categorize the specified error. If err == nil, it returns code.NoError. If err is a Code, it returns that code. If err is a Coder, it returns the reported code value. If err is context.Canceled, it returns code.Cancelled. If err is context.DeadlineExceeded, it returns code.DeadlineExceeded. Otherwise it returns code.SystemError.

func Register

func Register(value int32, message string) Code

Register adds a new Code value with the specified message string. This function will panic if the proposed value is already registered.

func (Code) Error

func (c Code) Error() string

type Coder added in v0.0.22

type Coder interface {
	Code() Code
}

A Coder is a value that can report an error code value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL