NAME

Text::Nunjucks::Lib::TemplateError - Nunjucks TemplateError (src/lib.js) -- name is always 'Template render error'

VERSION

version 0.001

DESCRIPTION

The error a failed template raises when the Environment is built with the dev option, a port of Nunjucks' TemplateError from src/lib.js. Without dev the same message and name arrive as a plain Text::Nunjucks::Lib::Error. Catch it with eval, or receive it as the first argument of a render callback.

my $env = Text::Nunjucks::Environment->new( [], { dev => 1 } );
eval { $env->render_string( '{% if %}', {} ); 1 } or do {
  my $err = $@;
  printf "%s at %d:%d\n%s\n", $err->name, $err->lineno, $err->colno, $err->message;
};

message

The text. For an error raised while a template renders it is prefixed with the template path and, for the first prefix, the line and column: (page.njk) [Line 3, Column 5] followed by a newline and the reason. An error from compiling a template (compile of Text::Nunjucks::Template, or the one get_exported hands to its callback) carries the bare reason.

name

Always Template render error.

lineno

The line of the template where the error happened. Errors from the parser and from throwOnUndefined count from 1; errors raised while rendering carry Nunjucks' own value, which counts from 0 (a\nb {{ foo() }} gives line 1, column 8, shown as [Line 1, Column 8]).

colno

The column, counted like "lineno".

cause

The error object this one wraps, when it was made from one (its message is then NAME: MESSAGE of the cause).

new

Text::Nunjucks::Lib::TemplateError->new( $message, $lineno, $colno );

Positional. $message is a string, or an error object with name and message that becomes the cause.

update

$err->update($path);

Prefixes the message with the template path (unknown path when it is empty) and, on the first call only, with the line and column. Called by the engine as the error travels up through the templates that included each other; returns the error.

SUPPORT

Issues

Please report bugs and feature requests at https://github.com/Getty/p5-text-nunjucks/issues.

CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

AUTHOR

Torsten Raudssus <getty@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> https://raudssus.de/.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.