⚠️ This is pre-release documentation for v3. For stable docs, visit v2.
Skip to content

@tmlmt/cooklang-parser / formatDiagnostic

Function: formatDiagnostic() ​

formatDiagnostic(diagnostic, source, label?): string

Renders a single Diagnostic as a human-readable string with a source code frame (caret pointer) when span information is available.

Parameters ​

diagnostic ​

Diagnostic

The diagnostic to render.

source ​

string

The original text returned in DiagnosticError.source or stored on DiagnosticError.source. Span positions refer to this string.

label? ​

string = "recipe"

Optional label shown in the location marker (default "recipe").

Returns ​

string

A multi-line plain-text string.

Example ​

error[COOKLANG_E0101]: Invalid quantity format: "%two"
  ┌─ recipe:1:12
  │
1 │ Add @flour{%two}
  │            ^^^^
  = fix: Use a number (3), range (1-2), or fraction (1/2).
  = see: https://cooklang-parser.tmlmt.com/v3/e/cooklang_e1001