FS FormScript
Package@formscript/errors
Specification14
Depends onnothing — it is a leaf

@formscript/errors

The error catalogue of §14 of the specification, and the diagnostic objects that carry it.

Every error a FormScript runtime reports has a stable, machine-readable code. The message text is not stable and must not be matched on; the code is.

The catalogue is generated

src/catalogue.generated.ts is produced from the specification's own §14 table by scripts/generate-catalogue.ts. A test asserts that the generated file matches the current specification, so the two cannot drift apart.

bash
npm run generate:catalogue

Each entry carries its code, its message, its category — the class that decides when the error is reported — and any notes:

ts
{
  code: 'E-REF-01',
  message: 'undefined reference',
  category: 'semantic',
  notes: '',
}

Diagnostics

ts
import { diagnostic } from '@formscript/errors';

const d = diagnostic('E-REF-01', {
  message: "unknown reference 'nmae'",
  location: { line: 12, column: 5, file: 'application.forms' },
  path: 'nmae',
  context: { suggestions: ['name'] },
});

diagnostic fills the message from the catalogue when none is given, and defaults the severity to error.

Suggestions

suggest and nearMisses use edit distance to propose likely intended names. They power the suggestions and near_misses context fields, which a runtime may show to the person who wrote the document.

Public API

17 exported symbols.

CatalogueEntry interface
catalogueMessage function
diagnostic function

Builds a diagnostic for a catalogue code. The code is the only required field; the message defaults to the catalogue's.

Diagnostic interface
DiagnosticContext interface
DiagnosticInit interface
editDistance re-export
ERROR_CATALOGUE const
ERROR_CODES const
ErrorCategory type

GENERATED FILE — do not edit. Source: FormScript-Language-Specification.md, section 14. Regenerate with: npm run generate:catalogue Verify with: npm test (pa…

ErrorCode type
isErrorCode function
nearMisses re-export
Severity type
SourceLocation interface
suggest re-export
SuggestionOptions interface