Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

wire.errors

import wire.errors

wire lifts part of this module out to its own top level; each name below is shown with the path that reaches it. Anything still spelled wire.errors.* needs import wire.errors.

The errors Wire raises, and the location information they carry.

Every one of them knows which template it came from and, where the problem can be traced to a specific tag, which line and column that tag started at. A template engine that can only say “something is wrong” is not much use once a layout hierarchy is a few files deep, so the location travels with the error rather than being reassembled by whoever catches it.

Classes

WireError

class wire.WireError < Error

The base class of every error Wire raises.

Catching this catches all of them, which is what a web handler wanting to turn any template failure into a 500 page should do.

import wire

catch {
  echo wire.render('dashboard')
} as e {
  if instance_of(e, wire.WireError) {
    echo 'template problem in ${e.path}: ${e.reason}'
  }
}

Fields

FieldTypeDescription
pathThe template the problem was found in: a file path for a template read from disk, or whatever was passed as…
lineThe line the offending tag started on, counting from 1, or 0 when the problem cannot be tied to one place…
columnThe column the offending tag started at, counting from 1, or 0.
reasonThe problem on its own, without the location that message glues onto the end of it.

Constructor

wire.WireError(reason: string, path: ?string, line: ?number, column: ?number)

Parameters

  • reason (string) — What went wrong, phrased without any location; the location is appended for you.
  • path (?string) — The template the problem is in. Defaults to <source>.
  • line (?number) — The line, counting from 1. Omit or pass 0 when there is no meaningful line.
  • column (?number) — The column, counting from 1.

WireError.location()

wire.WireError.location() -> string

Where the problem is, as path[line,column], or just the path when no line was recorded.

Returns string

TemplateNotFoundError

class wire.TemplateNotFoundError < WireError

Raised when a template file cannot be found, or when it resolves to somewhere outside the root directory.

A path that climbs out of the root with .. is reported as not found rather than as a permission problem, so a template cannot be used to probe the filesystem for what does and does not exist.

Constructor

wire.TemplateNotFoundError(reason: string, path: ?string, line: ?number, column: ?number)

Parameters

  • reason (string)
  • path (?string)
  • line (?number)
  • column (?number)

TemplateSyntaxError

class wire.TemplateSyntaxError < WireError

Raised while compiling a template, for anything Wire can tell is wrong without rendering: an unknown directive, an expression that does not parse, an x-elif with no x-if in front of it, a region defined twice.

Compilation happens once per template rather than once per render, so these surface the first time a template is used and not on every request after that.

Constructor

wire.TemplateSyntaxError(reason: string, path: ?string, line: ?number, column: ?number)

Parameters

  • reason (string)
  • path (?string)
  • line (?number)
  • column (?number)

RenderError

class wire.RenderError < WireError

Raised while rendering, for anything that depends on the values a template was given: iterating something that cannot be iterated, a filter that rejects its input, an include hierarchy that never bottoms out.

A variable that was simply not supplied is not one of these. Missing variables render as empty and test as falsy, which is what makes optional sections readable.

Constructor

wire.RenderError(reason: string, path: ?string, line: ?number, column: ?number)

Parameters

  • reason (string)
  • path (?string)
  • line (?number)
  • column (?number)

2026, Richard Ore and The Zuri Contributors