Help us shape the future of Go! Take the 2026 Go Developer Survey

errors

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNonSingularValue and ErrUnsupportedMutation are the errors of a MarshalJSONTo or UnmarshalJSONFrom method
	// which the root package calls, which wrote or read other than one value, or which declined after it wrote or
	// read, as encoding/json/v2 reports them.
	ErrNonSingularValue    = errors.New("must read or write exactly one value")
	ErrUnsupportedMutation = errors.New("unsupported calls must not read or write any tokens")
)
View Source
var (
	ErrDuplicateName = errors.New("duplicate object member name")
	ErrNonStringName = errors.New("object member name must be a string")
	ErrMaxDepth      = errors.New("exceeded max depth")
)

The errors of the JSON text, which jsontext reports by these very errors.

View Source
var (
	ErrUnknownName   = errors.New("unknown object member name")
	ErrAmbiguousName = errors.New("ambiguous object member name")
)

The errors of a member of an object which is unmarshaled into a struct, which the v2 json package reports in its SemanticError, by these very errors.

View Source
var ErrCycle = errors.New("encountered a cycle")

ErrCycle reports a value which is a value of itself, which JSON can't represent.

View Source
var ErrInvalidUTF8 = errors.New("invalid UTF-8")

ErrInvalidUTF8 reports invalid UTF-8 in a JSON string: jsontext and the v2 json package report it by this error.

Functions

func IsAtEnd added in v0.11.0

func IsAtEnd(err error) bool

IsAtEnd reports whether err is a syntax error of the end of the input ( see ErrSyntaxAtEnd ).

func MethodCallResult added in v0.12.0

func MethodCallResult(err error, depth int, n int64) (bool, error)

MethodCallResult returns the error of a call of MarshalJSONTo or UnmarshalJSONFrom with an encoder or a decoder of its own, which returned err, after which the stack of the encoder or the decoder is at the depth with n values at its top level, and whether the method declined: it returned errors.ErrUnsupported and wrote or read nothing.

func ShortPointer added in v0.12.0

func ShortPointer(p string) string

ShortPointer shortens a long pointer. The part which is left out is shown by an ellipsis for the end of the token which the start cuts, one for the whole tokens, and one for the start of the token which the end cuts.

func ValueStartAt added in v0.11.0

func ValueStartAt(err error) (int64, bool)

ValueStartAt returns the position of the byte of err, if it is the syntax error of a byte which is not the start of a value where one is waited for ( see WithValueStartAt ).

Types

type InvalidUTF8Error

type InvalidUTF8Error struct {
	S string // the whole string value that caused the error
}

func (*InvalidUTF8Error) Error

func (e *InvalidUTF8Error) Error() string

type InvalidUnmarshalError

type InvalidUnmarshalError struct {
	Type reflect.Type
}

func (*InvalidUnmarshalError) Error

func (e *InvalidUnmarshalError) Error() string

type MarshalerError

type MarshalerError struct {
	Type reflect.Type
	Err  error
	// contains filtered or unexported fields
}

A MarshalerError represents an error from calling a MarshalJSON or MarshalText method.

func ErrMarshaler

func ErrMarshaler(typ reflect.Type, err error, msg string) *MarshalerError

func (*MarshalerError) Error

func (e *MarshalerError) Error() string

func (*MarshalerError) Unwrap

func (e *MarshalerError) Unwrap() error

Unwrap returns the underlying error.

type MethodError added in v0.12.0

type MethodError struct {
	GoType reflect.Type
	Err    error
	Kind   MethodKind
	// Out is the output where the error is, of MethodJSONTo, which wrote to the encoder: the output before the
	// call if it is nil. Where is where its pointer points: the next value (+1), the last value (-1), or the
	// level the method stopped in (0).
	Out   []byte
	Where int8
}

MethodError is an error which a method or a function of marshaling returned, for the semantics of encoding/json/v2, which the encoder returns with the output written before the call: the v2 json package reports it at the place of that output, for the type of the value. How it reports an error which is itself one of its SemanticErrors depends on the method ( see MethodKind ).

func (*MethodError) Error added in v0.12.0

func (e *MethodError) Error() string

func (*MethodError) Unwrap added in v0.12.0

func (e *MethodError) Unwrap() error

type MethodKind added in v0.12.0

type MethodKind uint8

MethodKind is the method or the function which returned a MethodError, which encoding/json names in a MarshalerError by its String. The place of a SemanticError which it returns, for encoding/json/v2, is within the value it returns, after the place of the call, for MarshalJSON and a function of MarshalFunc; the error is reported as it is for MarshalText and AppendText; and it is given the place of the output where it stopped, if it has none, for MarshalJSONTo and a function of MarshalToFunc, which write to the encoder.

const (
	MethodMarshalJSON MethodKind = iota
	MethodMarshalFunc
	MethodMarshalText
	MethodAppendText
	MethodMarshalJSONTo
	MethodMarshalToFunc
)

func (MethodKind) String added in v0.12.0

func (k MethodKind) String() string

type OutputError added in v0.12.0

type OutputError struct {
	Out []byte
	Err error
}

OutputError is an error of the output Out, which the encoder wrote in a context of its own ( a value written by a default representation, or the value of an embedded fallback ): the v2 json package reports Err at the place of Out instead of the output which the encoder returns with it.

func (*OutputError) Error added in v0.12.0

func (e *OutputError) Error() string

func (*OutputError) Unwrap added in v0.12.0

func (e *OutputError) Unwrap() error

type PathError added in v0.10.0

type PathError struct {
	// contains filtered or unexported fields
}

func ErrEmptyPath added in v0.10.0

func ErrEmptyPath() *PathError

func ErrInvalidPath added in v0.10.0

func ErrInvalidPath(msg string, args ...any) *PathError

func (*PathError) Error added in v0.10.0

func (e *PathError) Error() string

type SemanticError added in v0.12.0

type SemanticError struct {
	GoType reflect.Type
	Err    error
}

SemanticError is an error of encoding a value of GoType by the semantics of encoding/json/v2, which the encoder returns with the output written before it: the v2 json package reports it as its SemanticError, at the place of that output.

func (*SemanticError) Error added in v0.12.0

func (e *SemanticError) Error() string

func (*SemanticError) Unwrap added in v0.12.0

func (e *SemanticError) Unwrap() error

type SyntaxError

type SyntaxError struct {
	Offset int64 // error occurred after reading Offset bytes
	// contains filtered or unexported fields
}

A SyntaxError is a description of a JSON syntax error.

func ErrExceededMaxDepth

func ErrExceededMaxDepth(c byte, cursor int64) *SyntaxError

func ErrExpected

func ErrExpected(msg string, cursor int64) *SyntaxError

func ErrInvalidBeginningOfValue added in v0.7.6

func ErrInvalidBeginningOfValue(c byte, cursor int64) *SyntaxError

func ErrInvalidCharacter

func ErrInvalidCharacter(c byte, context string, cursor int64) *SyntaxError

func ErrNotAtBeginningOfValue

func ErrNotAtBeginningOfValue(cursor int64) *SyntaxError

func ErrSyntax

func ErrSyntax(msg string, offset int64) *SyntaxError

func ErrSyntaxAtEnd added in v0.11.0

func ErrSyntaxAtEnd(msg string, offset int64) *SyntaxError

ErrSyntaxAtEnd is ErrSyntax for the end of the input, where more of it would have been read.

func ErrUnexpectedEndOfJSON

func ErrUnexpectedEndOfJSON(msg string, cursor int64) *SyntaxError

func WithValueStartAt added in v0.11.0

func WithValueStartAt(e *SyntaxError, cursor int64) *SyntaxError

WithValueStartAt marks e as the error of the byte at cursor, which is not the start of a value where one is waited for, and returns it.

func (*SyntaxError) Error

func (e *SyntaxError) Error() string

type TextError added in v0.12.0

type TextError struct {
	Err error
	// Name is the duplicate name, of ErrDuplicateName, which the pointer of the error points to.
	Name string
	// GoType is the type of the value which made the error, if the v2 json package reports it in a SemanticError,
	// as it does for a name which is not a string.
	GoType reflect.Type
	// Out is the output where the error is, if it is not the output which the encoder returns with it: a name of
	// an object which was written before.
	Out []byte
	// AtDelim is whether the offset of the error is the one of the comma which ends Out, before the name: the
	// place where encoding/json/v2 reports a name of an embedded fallback.
	AtDelim bool
}

TextError is an error of the JSON text which the encoder of the semantics of encoding/json/v2 would write, which it returns with the output written before it: the v2 json package reports it as jsontext.SyntacticError at the place of that output. Err is ErrInvalidUTF8, ErrDuplicateName or ErrNonStringName.

func (*TextError) Error added in v0.12.0

func (e *TextError) Error() string

func (*TextError) Unwrap added in v0.12.0

func (e *TextError) Unwrap() error

type UnmarshalError added in v0.12.0

type UnmarshalError struct {
	GoType reflect.Type
	Err    error
	// Start is the position of the value in the input, or of the bracket which ends an array for an error of the
	// length of the array. End is the position after the value if HasValue is set: the error reports the value, a
	// number or a string.
	Start, End int64
	HasValue   bool
	// NoKind is set for an error of the Go type, before the value is read: it reports no kind of JSON value.
	NoKind bool
	// Method is the method of unmarshaling, or the time type, which the value was read whole for and which returned
	// Err, which the v2 json package wraps as encoding/json/v2 wraps it, or whose read of the value failed with Err.
	Method UnmarshalMethod
}

UnmarshalError is an error of decoding the value at Start of the input into a value of GoType by the semantics of encoding/json/v2, which the decoder stops at: the v2 json package reports it as its SemanticError, at the place of the value, unless the input has a syntax error before it.

func (*UnmarshalError) Error added in v0.12.0

func (e *UnmarshalError) Error() string

func (*UnmarshalError) Unwrap added in v0.12.0

func (e *UnmarshalError) Unwrap() error

type UnmarshalFieldError deprecated

type UnmarshalFieldError struct {
	Key   string
	Type  reflect.Type
	Field reflect.StructField
}

An UnmarshalFieldError describes a JSON object key that led to an unexported (and therefore unwritable) struct field.

Deprecated: No longer used; kept for compatibility.

func (*UnmarshalFieldError) Error

func (e *UnmarshalFieldError) Error() string

type UnmarshalMethod added in v0.12.0

type UnmarshalMethod uint8

UnmarshalMethod is the method of unmarshaling of an UnmarshalError.

const (
	// UnmarshalByKind is an error of the value of its kind, which no method read.
	UnmarshalByKind UnmarshalMethod = iota
	// UnmarshalJSONMethod is an error of UnmarshalJSON or of a function of UnmarshalFunc: a SemanticError it returns
	// is within the value, after the place of the value. With ReportErrorsWithLegacySemantics, it is also the error of
	// UnmarshalJSONFrom or of a function of UnmarshalFromFunc, which encoding/json returns as it is.
	UnmarshalJSONMethod
	// UnmarshalTextMethod is an error of UnmarshalText or of the time.Time of a string: a SemanticError or a
	// SyntacticError it returns is reported as it is.
	UnmarshalTextMethod
	// UnmarshalWholeValue is the error of the text of a value which a stream read whole for its decoder, before it
	// decoded it, as encoding/json/v2 reads a value whole for a method, a function or a type of a string, a number or
	// bytes.
	UnmarshalWholeValue
)

type UnmarshalTypeError

type UnmarshalTypeError struct {
	Value  string       // description of JSON value - "bool", "array", "number -5"
	Type   reflect.Type // type of Go value it could not be assigned to
	Offset int64        // error occurred after reading Offset bytes
	Struct string       // name of the struct type containing the field, or of the root type ( see Error )
	Field  string       // the full path from root node to the field
	Err    error        // the cause of the error, or nil
}

An UnmarshalTypeError describes a JSON value that was not appropriate for a value of a specific Go type.

func (*UnmarshalTypeError) Error

func (e *UnmarshalTypeError) Error() string

Error returns the message of encoding/json of Go 1.27 ( see typeErrorMessage ).

func (*UnmarshalTypeError) Unwrap added in v0.11.0

func (e *UnmarshalTypeError) Unwrap() error

type UnsupportedTypeError

type UnsupportedTypeError struct {
	Type reflect.Type
}

An UnsupportedTypeError is returned by Marshal when attempting to encode an unsupported value type.

func (*UnsupportedTypeError) Error

func (e *UnsupportedTypeError) Error() string

type UnsupportedValueError

type UnsupportedValueError struct {
	Value reflect.Value
	Str   string
}

func (*UnsupportedValueError) Error

func (e *UnsupportedValueError) Error() string

Jump to

Keyboard shortcuts

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