Documentation
¶
Overview ¶
Package strictjson declares the error codes and the sentinels of the strict JSON decoder (not a codec), internal/service/data/codec/strictjson — range 0.3.72.* (ADR 0102 service/data/codec/strictjson block).
The codes live in the core at the path that mirrors the package emitting them (ADR 0160 §2) and keep the values they were allocated with: the LL byte 3 records the layer that allocated the range, not the directory that declares it today (ADR 0160 §3). Nothing here encodes or decodes — the mechanism, and the constructors that attach a failure's detail, stay in the service package.
Package strictjson — the sentinel *errs.Error values, one per code. Each Reason derives from its var name or from its Code constant (ADR 0020); the Public and Private texts are the ones the service package always emitted, so moving the declaration changed no rendering.
Every Public and every Private below is a fixed sentence. None of them can carry a byte of the document, because the document is what a caller least controls and an error message is where input classically leaks back out — into a response, into a log someone else reads.
Index ¶
Constants ¶
const CodeDecodeMisconfigured errs.Code = 0x00_03_48_08 // 0.3.72.8
CodeDecodeMisconfigured identifies a call the decoder refuses before reading anything: a non-positive bound, or a target that is not a non-nil pointer.
const CodeDocumentEmpty errs.Code = 0x00_03_48_02 // 0.3.72.2
CodeDocumentEmpty identifies a JSON document of zero bytes: no value at all, which a caller may read as "no body" rather than as a malformed one.
const CodeDocumentMalformed errs.Code = 0x00_03_48_03 // 0.3.72.3
CodeDocumentMalformed identifies a document that is not exactly one well-formed JSON value: a syntax error, a truncation, trailing data, a duplicated member name, or invalid UTF-8.
const CodeDocumentTooLarge errs.Code = 0x00_03_48_01 // 0.3.72.1
CodeDocumentTooLarge identifies a JSON document longer than the bound the caller gave.
const CodeDocumentUnreadable errs.Code = 0x00_03_48_07 // 0.3.72.7
CodeDocumentUnreadable identifies a reader that failed before the document ended — a connection reset, a cancelled request.
const CodeMediaTypeUnsupported errs.Code = 0x00_03_48_06 // 0.3.72.6
CodeMediaTypeUnsupported identifies a request body whose Content-Type is not application/json or a +json structured-syntax type.
const CodeMemberUnknown errs.Code = 0x00_03_48_04 // 0.3.72.4
CodeMemberUnknown identifies an object member the target type does not declare.
const CodeValueMismatched errs.Code = 0x00_03_48_05 // 0.3.72.5
CodeValueMismatched identifies a well-formed value the target cannot hold: the wrong JSON kind, a number out of the field's range, a value a field's own unmarshaler refused.
Variables ¶
var ( // DocumentTooLarge refuses a document longer than the caller's bound, // whatever the bytes beyond it would have said. DocumentTooLarge = errs.Define(CodeDocumentTooLarge, "DOCUMENT_TOO_LARGE", "The JSON document is larger than the limit", "service/data/codec/strictjson: more bytes arrived than the bound allows; the limit field is the bound", errs.WithHTTPStatus(httpContentTooLarge), errs.WithExitCode(exitDataErr)) // DocumentEmpty reports a document of zero bytes. It is its own code so a // caller for whom a body is optional can tell "no body" from "a broken // one" without reading the input again. DocumentEmpty = errs.Define(CodeDocumentEmpty, "DOCUMENT_EMPTY", "The JSON document is empty", "service/data/codec/strictjson: the reader ended before the first byte", errs.WithHTTPStatus(httpBadRequest), errs.WithExitCode(exitDataErr)) // DocumentMalformed refuses a document that is not exactly one // well-formed JSON value. DocumentMalformed = errs.Define(CodeDocumentMalformed, "DOCUMENT_MALFORMED", "The JSON document is not well-formed", "service/data/codec/strictjson: a syntax error, a truncation, trailing data, a duplicate name or invalid UTF-8; the offset field locates it", errs.WithHTTPStatus(httpBadRequest), errs.WithExitCode(exitDataErr)) // MemberUnknown refuses an object member the target does not declare, // including one that differs from a declared name only by case. MemberUnknown = errs.Define(CodeMemberUnknown, "MEMBER_UNKNOWN", "The JSON document has a member the target does not accept", "service/data/codec/strictjson: an object member matches no field of the target; PointerOf locates it", errs.WithHTTPStatus(httpBadRequest), errs.WithExitCode(exitDataErr)) // ValueMismatched refuses a well-formed value the target cannot hold. ValueMismatched = errs.Define(CodeValueMismatched, "VALUE_MISMATCHED", "The JSON document has a value of the wrong type or out of range", "service/data/codec/strictjson: a value does not fit the field it maps to; PointerOf locates it", errs.WithHTTPStatus(httpBadRequest), errs.WithExitCode(exitDataErr)) // MediaTypeUnsupported refuses a request body that does not declare itself // JSON. MediaTypeUnsupported = errs.Define(CodeMediaTypeUnsupported, "MEDIA_TYPE_UNSUPPORTED", "The request body must be application/json or a +json media type", "service/data/codec/strictjson: the Content-Type is absent, unparsable, or names another media type", errs.WithHTTPStatus(httpUnsupportedMediaType), errs.WithExitCode(exitDataErr)) // DocumentUnreadable wraps a reader that failed before the document // ended. The reader's own error stays in the chain. DocumentUnreadable = errs.Define(CodeDocumentUnreadable, "DOCUMENT_UNREADABLE", "The JSON document could not be read", "service/data/codec/strictjson: the reader returned an error other than end-of-input", errs.WithHTTPStatus(httpBadRequest), errs.WithExitCode(exitIOErr)) // DecodeMisconfigured refuses a call the decoder can never honour: a // non-positive bound — whose two readings, "unbounded" and "nothing", are // opposites (ADR 0031) — or a target that is not a non-nil pointer. DecodeMisconfigured = errs.Define(CodeDecodeMisconfigured, "DECODE_MISCONFIGURED", "The JSON decoder was called with an argument it cannot use", "service/data/codec/strictjson: the field names the argument: a non-positive bound or a target that is not a non-nil pointer", errs.WithExitCode(exitSoftware)) )
Functions ¶
This section is empty.
Types ¶
This section is empty.