Errors and exits
FormaSL errors are typed diagnostics or typed application outcomes. Do not use a substring of a text-rendered message as a programmatic contract; request JSON revision 1 or use the Rust facade when an integration needs structured fields.
First distinction: usage, rejection, driver, outcome
| Situation | Typical exit | What to do |
|---|---|---|
| unknown verb, missing required option, invalid option value | 2 | correct the command line; no source program has been evaluated |
| source parses/checks/rejects | 1 | read the diagnostic code and locus, then repair the source set |
| source/plan cannot be read or a projection cannot be made | 3 | repair the path, encoding, permissions, or requested schema revision |
| selected application is unsupported | 4 | choose a supported operation or keep the boundary explicit; do not simulate a result |
| reasoning budget exhausted | 5 | inspect the outcome, then choose and record a larger budget if appropriate |
run can also return a rejected aggregate with exit 1. An exit code is only
the top-level category: inspect the output’s per-application outcome and its
diagnostics before deciding how to recover.
Diagnostic classes
The facade classifies diagnostics as:
normative_rejection— a source/program invariant was violated;product_binding— an input set, import, or product-level binding is incoherent;driver— input/output, command, or external driver boundary failure;internal— an implementation invariant failure that should be reported with a minimal reproducer.
Common codes include:
| Code | Meaning | Recovery |
|---|---|---|
UNEXPECTED_TOKEN | lexer or parser could not admit the token in that position | start from a small accepted module; check quotes, braces, commas, and reserved words |
MALFORMED_RANGE | a bounded range has its lower bound above its upper bound | use an ordered range such as 0..1 or an open upper bound such as 0..* |
INVALID_UNBOUNDED_PATH_FORMATION | a path body declares an unbounded repeat (for example repeat 1..*) | give the path a finite upper bound so the route is checkable |
UNRESOLVED_REFERENCE | a name did not resolve in the current checked source set | declare it earlier, use a valid import, and pass every imported .fsl input |
AGGREGATE_GROUP_CORRELATION_REQUIRED | a rule-aggregate by ?key compatibility shorthand has zero DISTINCT exact-source candidate roles over the whole semantic rule | author the explicit correlation (by Source.role as ?key or by Source.role); a binder bound only by a different relation is not a source candidate |
AMBIGUOUS_AGGREGATE_GROUP_CORRELATION | the shorthand by ?key is positively bound by more than one DISTINCT role of the exact aggregate source | author by Source.role as ?key per intended component; correlation is never decided by spelling, order, type, or first match |
AGGREGATE_GROUP_BINDER_COLLISION | a MemberDerived output binder is introduced by more than one component, or collides with the aggregate result binder | use distinct output binders (as ?v), distinct from the aggregate’s result variable |
IMPORT_CYCLE | provided modules form an import cycle | break the cycle; imports must be acyclic |
DUPLICATE_SOURCE_REFERENCE | two SourceInput values use the same reference | give each supplied source a unique reference |
DUPLICATE_MODULE_NAME | two inputs declare the same module name | give modules distinct names or pass only the intended revision |
EMPTY_SOURCE_SET | the facade was called without source inputs | supply at least one complete module |
UNKNOWN_APPLICATION | --app or a facade selection names no checked application | use inspect --view applications and select the exact name |
RULE_WIRE_REJECTION | a rule’s using target resolves to a declaration kind with no defined rule-basis semantics (only theory/ontology authority and relation/content dependency coordinates are admissible) | re-point the rule at a theory, ontology, relation, or content basis; the source may parse, but it is not executable on the public reasoning path |
PROJECT_MODE_CONFLICT | explicit .fsl operands were combined with project flags, or a project-only flag was supplied to a command that rejects it | choose one mode: either explicit file operands or project flags, never both |
PORTABLE_PATH_INVALID | a package source-rebind/source-new --path value violates the portable-path grammar | use a package-relative path per the frozen release-contract grammar |
DRIVER_IO | the CLI cannot read an input path | correct the path or file permissions; keep .fsl and .fsp inputs explicit |
The parser’s source locus identifies the actual source span. Preserve it with a reproducer rather than replacing a rejected source with a dummy default.
Current surface-shape recovery
Several UNEXPECTED_TOKEN diagnostics are best repaired by checking the actual
header shape, rather than changing names at random:
| Intent | Implemented spelling | Frequent non-working sketch |
|---|---|---|
| selective module import | import Q { Name as Local } | import Q::{Name} or import Q::* |
| import a claim | import claim Q as local_claim | claim import Q … |
| constraint parameters | constraint Name using Basis($x: Type) { … } | constraint Name($x: Type) using Basis { … } |
| revision application | revise Name($x: Type) using Basis { … } | adding from $base to revise |
| source evolution | evolve source Name(…) using Basis from $base { by: $editor … } | omitting the required by: header |
| realization binding | bind capability to external "reference" | using $variable, ?witness, or a .fsl pure call as a realization value |
For a source import failure, pass the full import closure as explicit .fsl
operands. For a realization failure, retain exactly one .fsp --for plan and
check that every target it names exists in the checked program. See the
Language guide for the broader surface reference.
Intentional command-line failures
run has no hidden gas default:
formasl run examples/hello.fsl
realize has no hidden plan default:
formasl realize examples/hello.fsl
Both are command-line usage failures (exit 2). The recovery is to add the
required --gas N or exactly one --for PLAN.fsp; do not reinterpret a
missing argument as an empty resource budget or empty realization.
Machine-output failures
A JSON projection can fail closed when a frozen schema revision cannot represent
the observed run result. Use --schema-revision 1 for a new machine consumer.
That is not a conversion of the underlying semantic result; it selects the
current successor representation.
Reporting a defect
When a result looks inconsistent, report:
- the exact CLI command or facade request;
- every supplied
.fsland.fspsource (or a minimal redacted reproducer); - the exit status, diagnostic codes, and requested schema revision;
- whether a realization plan was supplied; and
- the expected typed outcome versus the actual one.
This separates an invalid command, rejected input, finite gas budget, and an implementation defect without guessing from prose alone. See Toolchain and CLI for the complete exit table.