Tagscript

TemplateError

TagScript


Class: TemplateError

Defined in: packages/tagscript/src/lib/Errors/index.ts:28

Raised by a parser when the template is wrong: a malformed payload, a parameter that cannot be read, a value the parser cannot make sense of.

The person who wrote the template is usually not the person running the process, and has no console to read, so the interpreter renders message into the output in place of the tag that raised it and carries on with the rest of the template. The error is also pushed onto Response.errors so the host application can inspect it.

Write messages for a template author, not for a developer.

Example

public parse(ctx: Context) {
	const seconds = Number.parseInt(ctx.tag.parameter!, 10);
	if (Number.isNaN(seconds)) throw new TemplateError('cooldown needs a number of seconds', ctx.tag.declaration);
	return '';
}

Extends

Constructors

Constructor

new TemplateError(message, tag?, options?): TemplateError

Defined in: packages/tagscript/src/lib/Errors/index.ts:36

Parameters

message

string

tag?

string | null

options?

ErrorOptions

Returns

TemplateError

Overrides

TagScriptError.constructor

Properties

cause?

optional cause?: unknown

Defined in: node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:24

Inherited from

TagScriptError.cause


message

message: string

Defined in: node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1075

Inherited from

TagScriptError.message


name

name: string = 'TemplateError'

Defined in: packages/tagscript/src/lib/Errors/index.ts:29

Overrides

TagScriptError.name


stack?

optional stack?: string

Defined in: node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076

Inherited from

TagScriptError.stack


tag

readonly tag: string | null

Defined in: packages/tagscript/src/lib/Errors/index.ts:34

The declaration of the tag that raised this, when the parser passed it.

Methods

isError()

static isError(error): error is Error

Defined in: node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.esnext.error.d.ts:21

Indicates whether the argument provided is a built-in Error instance or not.

Parameters

error

unknown

Returns

error is Error

Inherited from

TagScriptError.isError

On this page