Documentation
¶
Overview ¶
Package refusal is the registry of abcd's refusal codes (itd-2610301428378830, spc-2610301431108175 step 1).
When abcd refuses a call (exit 2, or exit 3 when someone else holds what the call needs), the refusal carries a short code, a one-line hint and the next command to try, and `abcd explain <code>` prints the code's explanation. Every code is one entry of the table below, and the front door reads the hint, the next command and the explanation from it, so a refusal and its explanation cannot disagree.
A code is a short name, never a number (adr-2610301638558260): the verb, a slash and the reason, in lower-case kebab-case, such as capture/missing-remedy, or usage/... for the command framework's own refusals. Once a release has carried a code it is never renamed and never given to a different refusal: a refusal that changes meaning gets a new code, and one that goes away keeps its entry, marked retired, so explain still answers and the name is never handed out again. The words of an entry can change in any release; only the code is a promise.
The registry is held by tests: no two entries share a code, every code follows the grammar, every Code constant is registered, and the committed ledger (LedgerPath), written from the table by cmd/refusal-codes-sync, is the one the release guard reads at the last tag.
The package is transport-free: it holds data and two small helpers, Wrap and CodeOf, which let a core package name the code where the refusal is decided and the front door find it however the error was wrapped.
Index ¶
Constants ¶
const CommandSlot = "{command}"
CommandSlot is the placeholder in a next-command template that FillNext replaces with the refused call's own command path, below the root. It is the only part of a next command filled at run time, and it is never filled from the caller's arguments.
const LedgerFormatVersion = 1
LedgerFormatVersion is the ledger's format version.
const LedgerPath = ".abcd/development/release/refusal-codes.json"
LedgerPath is the committed ledger of codes, from the repository root. The release guard reads it at the last tag and refuses a cut in which a code it lists is missing.
const NoNext = "none"
NoNext is the next command of an entry where no command can help, such as a refusal that says to wait for someone else.
Variables ¶
This section is empty.
Functions ¶
func EncodeLedger ¶
EncodeLedger renders a ledger as the committed file holds it.
func FillNext ¶
FillNext fills a next-command template from the refused call's command path (`abcd capture remedy`): CommandSlot becomes the words below the root, or the root's own name for the root, as `abcd explain` takes them.
func IsTemplate ¶
IsTemplate reports whether next is a template, a command holding placeholders the caller fills in before running it, rather than a command to run as it stands.
Types ¶
type Code ¶
type Code string
Code is a refusal code: `<verb>/<reason>`.
const ( // The command framework's usage refusals, raised by every command. UsageUnknownCommand Code = "usage/unknown-command" UsageUnknownFlag Code = "usage/unknown-flag" UsageMissingArgument Code = "usage/missing-argument" UsageExtraArgument Code = "usage/extra-argument" UsageFlagConflict Code = "usage/flag-conflict" UsageMissingRequiredFlag Code = "usage/missing-required-flag" UsageInvalidFlagValue Code = "usage/invalid-flag-value" // capture's own refusals. CaptureMissingRemedy Code = "capture/missing-remedy" CaptureRemedyMachineSpecific Code = "capture/remedy-machine-specific" CaptureUnknownIssue Code = "capture/unknown-issue" // CaptureUnknownReadingRecord is an id the reading ledger does not hold: // a reading item, an admission, a disposition or a reframe. CaptureUnknownReadingRecord Code = "capture/unknown-reading-record" CaptureNotOpen Code = "capture/not-open" CaptureInsufficientGrounds Code = "capture/insufficient-grounds" CaptureInvalidInput Code = "capture/invalid-input" CaptureNotCharacterized Code = "capture/not-characterized" // explain's own refusals. ExplainUnknownPath Code = "explain/unknown-path" ExplainUnrecognizedInput Code = "explain/unrecognized-input" ExplainUnknownCode Code = "explain/unknown-code" )
The registered codes. Each constant is an entry of the table below; a test fails on a constant the table does not hold.
const None Code = ""
None is the absence of a code. A refusal built with None at exit 2 or 3 is carried out as Uncoded.
const Uncoded Code = "internal/uncoded"
Uncoded is the code a refusal carries when it was built without one at exit 2 or 3. It is never registered, so `abcd explain` refuses it and the tests that hold the registry and the front door fail on it.
type Entry ¶
type Entry struct {
// Code is the code itself, the one part a release promises.
Code Code `json:"code"`
// Summary is the one-line hint a refusal carrying the code shows.
Summary string `json:"summary"`
// Explanation is a few lines `abcd explain <code>` prints: what the
// refusal means and how to get past it.
Explanation string `json:"explanation"`
// Next is the command to try next, or NoNext where no command can help.
// It may hold CommandSlot, which the front door fills. A next holding a
// placeholder (`<fix>`, a word in angle brackets) is a template whose
// placeholders the caller fills in before running it (IsTemplate); any
// other next runs as it stands.
Next string `json:"next"`
// RaisedBy names the command paths that raise the code. It is empty for
// a usage code, which every command raises.
RaisedBy []string `json:"raised_by,omitempty"`
// Retired is the release tag the code was retired in, empty while the
// code is live. A retired entry stays in the table for good.
Retired string `json:"retired,omitempty"`
// ReplacedBy is, for a retired code, the code that took its place, if
// one did.
ReplacedBy Code `json:"replaced_by,omitempty"`
}
Entry is one registered code.
type Ledger ¶
type Ledger struct {
FormatVersion int `json:"format_version"`
Codes []LedgerEntry `json:"codes"`
}
Ledger is the committed list of codes: only the codes and their retirement, since an entry's words may change in any release and the code may not.
func BuildLedger ¶
func BuildLedger() Ledger
BuildLedger is the ledger of the registry, sorted by code.
func DecodeLedger ¶
DecodeLedger reads a committed ledger, refusing a format version it does not know, a code that does not follow the grammar, and a replaced_by that is set on a live code, names itself, or names a code the ledger does not list.
type LedgerEntry ¶
type LedgerEntry struct {
Code Code `json:"code"`
Retired string `json:"retired,omitempty"`
ReplacedBy Code `json:"replaced_by,omitempty"`
}
LedgerEntry is one code of the ledger.