Errors and Diagnostics
The library emits two kinds of signals:
- Errors (
Error) stop the current call and are thrown; the caller must handle them. - Diagnostics (
WikitextDiagnostic) record a local problem or degradation on the snapshot without aborting the page.
Error classes
Every error carries code; cause keeps the underlying error. WikitextPrepareError.stage records the failing stage, commonly prepare, wikitext, rehype, or finalize.
Exports by entry
Error codes
In the default mode, expansion preserves calls and records diagnostics; with strict: true, recoverable failures above are thrown.
Handling examples
- Never branch on
messagetext; usecode(andstagewhen relevant). - Catch parse and prepare errors at the call site and distinguish budgets, config, and plugins.
- Report view failures through
onRenderError; the error boundary replaces only the failed top-level block. - Do not silently fall back to reparsing when restoring a snapshot fails; check the version and the source first.
Diagnostics
positionandoriginrefer to the normalized source; generated content may have no origin.ruleidentifies the rule or plugin that produced the record.- Render snapshot diagnostics merge parse, preparation, and finalization records.
- A single diagnostic never aborts the page; the host decides whether to report or block.
Related
- Troubleshooting: narrow down by symptom.
- Preparation
/hast: prepare-stage and plugin errors. - Expansion
/expand:strictmode and expansion errors.