Documentation
¶
Overview ¶
Package decodeerr reduces an encoding/json/v2 decode error to the parts of it that are safe and stable to hand a client (SONNY-4078).
The Error() text of a *json.SemanticError is neither: json/v2 picks its modal verb ("cannot" vs "unable to") once per process, by design, so the same refusal reads differently from one server process to the next, and it names the Go type being decoded into. Classify keeps only the JSON pointer of the offending value and a fixed cause phrase chosen from the error's sentinel, so the refusal is identical in every process and carries nothing about the server's implementation. Callers log the raw error separately.
Index ¶
Constants ¶
const ( // UnknownMember: an object member the target type does not declare // (json.ErrUnknownName under RejectUnknownMembers). UnknownMember = "unknown member" // DuplicateMember: an object member named twice (jsontext.ErrDuplicateName). DuplicateMember = "duplicate member" // InvalidType: a JSON value of the wrong kind for its target (a string // where a number is declared, an array where an object is, ...). InvalidType = "invalid type" // InvalidValue: a JSON value of the right kind that the target refuses // (an out-of-range number, a custom unmarshaler's refusal, ...). InvalidValue = "invalid value" // MalformedJSON: input that is not valid JSON (truncated, bad syntax, // invalid UTF-8, ...). MalformedJSON = "malformed JSON" )
Stable cause phrases. They are part of the client-facing contract: change one only as a breaking change.
const MaxPointerBytes = 256
MaxPointerBytes bounds the JSON pointer echoed back to a client. The pointer is built from client-supplied member names, so an unbounded one would let a request make the refusal arbitrarily large; a longer pointer is cut at MaxPointerBytes and ends in TruncationMarker, which marks it as no longer a usable pointer.
const TruncationMarker = "...(truncated)"
TruncationMarker ends a pointer that was cut at MaxPointerBytes.
Variables ¶
This section is empty.
Functions ¶
func Classify ¶
Classify returns the stable cause phrase and the JSON pointer (RFC 6901; "" for the whole document or when unknown) for a decode error returned by encoding/json/v2. An error that is not a json/v2 decode error is reported as MalformedJSON with no pointer.
func Validation ¶ added in v0.25.0
Validation reports the fixed cause phrase and the sanitized JSON pointer of a generated Valid() refusal anywhere on err's chain, and ok=false for any other error. The pointer is sanitized like a decode error's (controls and bidi overrides drop it, a long one is truncated): it can hold map keys the client chose.
Types ¶
This section is empty.