@tola/diagnostic
Emit custom errors, warnings, info messages, and hints during Typst evaluation.
Import
#import "@tola/diagnostic:0.0.0": *Exports
report
let report(
message: str,
at: content | none | auto = auto,
code: str | none = none,
hints: array = (),
related: array = (),
severity: str = "warning",
) = none;Record a site diagnostic without immediately aborting Typst evaluation.
Any "error" diagnostic fails tola check and tola build after evaluation finishes, while "warning", "info", and "hint" allow the build to succeed. Use Typst’s panic(...) only when evaluation cannot continue.
Positional parameters
messagestrrequired: Human-readable explanation of the issue.
Named parameters
severitystrdefault:"warning": Diagnostic level:"error","warning"(default),"info", or"hint".codestr | nonedefault:none: Optional rule identifier owned by your site or module (for example"missing-summary").atcontent | none | autodefault:auto: Location anchor:auto(default) points to thereport(...)call, Typst content points to that element’s source span, andnoneomits location.hintsarraydefault:(): Optional array of short fix suggestions shown below the message.relatedarraydefault:(): Optional array of(message: str, at: content | none)records pointing to related spans.
Warn when an article omits a description
#import "@tola/diagnostic:0.0.0": report
#let check-page(title, description) = {
if description == none {
report(
"Page \"" + title + "\" is missing a description.",
severity: "warning",
code: "site.missing-description",
hints: ("Add `description` in `tola-meta`.",),
)
}
}