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

env.errors

import env.errors

env 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 env.errors.* needs import env.errors.

Every error the env module raises, under one root.

EnvError is that root. The three subclasses separate the cases worth handling differently: a file that will not parse, a file that was demanded and is not there, and a variable a program cannot run without.

Each one carries the detail a message alone cannot. ParseError knows the line and column it stopped at, MissingFile knows the path it looked for, and MissingVariable knows the name it wanted.

Classes

EnvError

class env.EnvError < Error

Base class for every error this module raises.

Catch this to catch anything env can do.

  • printable — has a @to_string(), so echo and print() show something useful

Constructor

env.EnvError(message)

EnvError.to_string()

env.EnvError.to_string()

ParseError

class env.ParseError < EnvError

A source could not be parsed.

line and column are both 1-based and point at the character the parser gave up on, which is where the fix goes.

catch {
  env.parse('12FACTOR=yes')
} as error {
  echo '${error.message} (line ${error.line}, column ${error.column})'
}
  • printable — has a @to_string(), so echo and print() show something useful

Fields

FieldTypeDescription
linenumberThe 1-based line the parser stopped at.
columnnumberThe 1-based column within that line.

Constructor

env.ParseError(message: string, line: number, column: number)

Parameters

  • message (string)
  • line (number)
  • column (number)

ParseError.to_string()

env.ParseError.to_string()

MissingFile

class env.MissingFile < EnvError

A file the loader was told to require is not there.

Only Loader.required() produces this. A loader left at its default treats an absent file as an empty one and records the path in Result.missing instead.

  • printable — has a @to_string(), so echo and print() show something useful

Fields

FieldTypeDescription
pathstringThe path that was looked for, after ~ was expanded.

Constructor

env.MissingFile(path: string)

Parameters

  • path (string)

MissingFile.to_string()

env.MissingFile.to_string()

MissingVariable

class env.MissingVariable < EnvError

A variable a program said it needed is not configured.

Raised by require() and by the ${NAME:?reason} form during expansion.

  • printable — has a @to_string(), so echo and print() show something useful

Fields

FieldTypeDescription
namestringThe name of the variable that was wanted.

Constructor

env.MissingVariable(name: string, message: ?string)

Parameters

  • name (string)
  • message (?string) — A reason to use instead of the default text.

MissingVariable.to_string()

env.MissingVariable.to_string()

2026, Richard Ore and Zuri contributors