Skip to content

Errors ​

See the Errors guide for usage.

ErrorTemplate ​

ts
class ErrorTemplate {
	readonly options: Readonly<Required<ErrorTemplateOptions>>;
	constructor(options?: ErrorTemplateOptions);

	render(data: ErrorData): string;
	sections(data: ErrorData): string[];
	formatErrors(data: ErrorData): string;
	formatError(error: JinjuError): string;
	formatHint(data: ErrorData): string;
	formatCommand(data: ErrorData): string;
}

Renders error output, which is printed to stderr, from ErrorData. Extend it and override any method to change part of it, or render to replace it.

MethodDefault
renderJoins sections with blank lines and adds a trailing newline
sections[errors, hint]. The hint is left out with hint: false
formatErrorsOne line per error, from formatError
formatErrorerror: <message>
formatHintRun 'app my-site deploy --help' for usage.
formatCommandThe command as typed, e.g. app my-site deploy

ErrorTemplateOptions ​

ts
interface ErrorTemplateOptions {
	hint?: boolean;
}

hint adds a "Run '… --help' for usage." line. Defaults to true.

ErrorData ​

ts
interface ErrorData {
	program: HelpProgram;
	errors: readonly JinjuError[];
	path: readonly HelpPathPart[];
	words: readonly string[];
	help: HelpData;
}
FieldDescription
programThe program's name, version and description.
errorsThe errors, in the order found.
pathThe matched command path, e.g. <project> deploy. Empty at the root.
wordsThe command path as typed, e.g. ['my-site', 'deploy'].
helpThe matched level's HelpData, e.g. to show usage.

JinjuError ​

ts
class JinjuError extends Error {}

The base class for every error Jinju produces. Throw it (or a subclass) from run to report a problem with exit code 1.

ConfigError ​

ts
class ConfigError extends JinjuError {}

Thrown synchronously when flags, args or commands are defined in a conflicting way, such as two flags with the same alias, or an invalid command tree.

UnknownCommandError ​

ts
class UnknownCommandError extends JinjuError {
	readonly command: string;
}

Unknown command '<command>'.

UnknownFlagError ​

ts
class UnknownFlagError extends JinjuError {
	readonly flag: string;
}

Unknown flag '<flag>'. Only reported in strict mode, which is the default.

UnexpectedArgError ​

ts
class UnexpectedArgError extends JinjuError {
	readonly arg: string;
}

Unexpected argument '<arg>': a positional value with no arg to take it.

MissingRequiredError ​

ts
class MissingRequiredError extends JinjuError {
	readonly label: string;
}

Missing required <label>, where label is e.g. --token or argument <name>.

MissingValueError ​

ts
class MissingValueError extends JinjuError {
	readonly label: string;
}

<label> requires a value: a value flag with nothing after it.

DuplicateFlagError ​

ts
class DuplicateFlagError extends JinjuError {
	readonly label: string;
}

<label> can only be provided once: a flag that isn't .multiple() given more than once.

InvalidValueError ​

ts
class InvalidValueError extends JinjuError {
	readonly label: string;
	readonly input: string;
	readonly reason: string;
}

Invalid value '<input>' for <label>: <reason>. reason is the parser's error message. For values read from an environment variable, label names it, e.g. --port (from $PORT).