Documentation
¶
Overview ¶
Package problem decodes the Normatik public API's RFC-7807 ProblemDetail responses and maps them to actionable CLI output + exit codes.
Design choice (the CLI's value-add): we decode the RAW error body into a generic map so that EVERY field — including hint fields the CLI does not yet know about — is preserved (Raw). Known fields are additionally lifted into typed fields for ergonomic access. Exit-code policy lives in one place (internal/catalog.ExitFor); the synthesized "next command" is a data-driven registry keyed by errorCode rather than a growing switch.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Diagnostic ¶
type Extra ¶ added in v1.0.0
type Extra struct {
Key string
Value json.RawMessage
}
Extra is one server-sent ProblemDetail member the CLI has no typed field for (e.g. conflictingPageId, blockingDescriptors, totalCount). Value is the verbatim JSON so nothing is lost or reinterpreted.
func (Extra) ScalarText ¶ added in v1.0.0
ScalarText renders a JSON scalar (string, number, bool) as plain text and reports false for null, arrays and objects — table mode prints only scalars.
type FieldError ¶ added in v1.0.0
FieldError is one entry of a BindException-style errors[] array. Field is the server path (e.g. "description" or "values[0].value"), not a CLI flag.
func (FieldError) Line ¶ added in v1.0.0
func (e FieldError) Line() string
Line formats the field error as "field: message". Nested paths stay as-is.
type Problem ¶
type Problem struct {
Status int
Title string
Detail string
ErrorCode string
Hint string
Reason string
ValidKeys []string
ValidNames []string
InvalidKeys []string
UnknownKeys []string
ValidValues []string
AllowedMethods []string
CurrentStatus string
RequestedAction string
RequiredRole string
Field string
ReceivedValue string
MinValue string
MaxValue string
ReceivedZone string
EntityType string
CurrentVersion string
UsageCount *int
// RetryAfterSeconds and InTrash drive recovery suggestions.
RetryAfterSeconds *int
InTrash bool
Diagnostics []Diagnostic
Errors []FieldError
Raw map[string]json.RawMessage
}
Problem is a decoded ProblemDetail. Known fields are typed; Raw holds every field verbatim for forward-compatible surfacing.
func Decode ¶
Decode parses an error body. ok=false means the body is NOT a recognizable ProblemDetail (e.g. a Tomcat HTML 404) — callers treat that as a distinct "malformed backend response" class instead of pretending it has an errorCode.
func (*Problem) ExitCode ¶
ExitCode maps a problem to a stable, documented exit code (see `explain exit-codes`). The policy is centralized in catalog.ExitFor so the CLI and the generated catalogue can never disagree. Agents branch on the exit code first, then on the errorCode for precision.
func (*Problem) Extras ¶ added in v1.0.0
Extras returns the untyped members of the decoded body in key order. This is the forward-compatibility contract of Raw: a new server hint field surfaces in the envelope (and, when scalar, in table mode) without a CLI release.
func (*Problem) Suggestion ¶
Suggestion synthesizes a runnable "next command" from the structured hint fields, so an agent (or human) can self-correct in one loop.