Docs menu
import { ExecError, ParseError, TemplateError } from '@memomori/obol/errors'
Class Thrown when
ParseError parse meets bad syntax or an unknown function
ExecError execute fails, or a function you added throws
TemplateError the base of both, and thrown alone for misuse, such as a bad option

Messages match Go's, with the template name, line and column:

template: page:3: function "upcase" not defined
template: page:3:9: executing "page" at <.user.email>: map has no entry for key "email"

An ExecError carries templateName, the template that was running. When a function you added throws, cause holds what it threw:

try {
  page.execute(data)
} catch (error) {
  if (error instanceof ExecError && error.cause) report(error.cause)
  throw error
}

What fails #

Parsing fails on:

  • an unclosed action, string or comment
  • an {{end}}, {{else}}, {{break}} or {{continue}} out of place
  • an undefined variable or function

A run fails on:

  • a call to a template no one defined
  • a field a class instance lacks, or a key on null
  • index or slice out of range
  • a builtin given the wrong number or kind of arguments
  • a missing key, under missingkey=error
  • templates nested over 250 calls deep

The text printed before the failure is lost; execute returns all or nothing.