problem

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 7 Imported by: 0

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 Diagnostic struct {
	Code      string `json:"code"`
	Severity  string `json:"severity"`
	Line      int    `json:"line"`
	Column    int    `json:"column"`
	EndColumn int    `json:"endColumn"`
	Message   string `json:"message"`
}

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

func (e Extra) ScalarText() (string, bool)

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

type FieldError struct {
	Field   string `json:"field"`
	Message string `json:"message"`
}

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

func Decode(status int, body []byte) (*Problem, bool)

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) Error

func (p *Problem) Error() string

func (*Problem) ExitCode

func (p *Problem) ExitCode() int

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

func (p *Problem) Extras() []Extra

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

func (p *Problem) Suggestion(base string) string

Suggestion synthesizes a runnable "next command" from the structured hint fields, so an agent (or human) can self-correct in one loop.

Jump to

Keyboard shortcuts

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