From ad91490664d34c121c0efa96441320ea8949233a Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 1 Mar 2026 17:38:05 +0200 Subject: Add error context to eval-based template processing Template eval failures now log the template file path and the failing code block/line, making it much easier to debug syntax errors in .gmi.tpl templates. Co-Authored-By: Claude Opus 4.6 --- lib/template.source.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/template.source.sh b/lib/template.source.sh index 5d9f4dd..b93303e 100644 --- a/lib/template.source.sh +++ b/lib/template.source.sh @@ -82,7 +82,11 @@ template::_generate () { while IFS='' read -r line; do if [ "$is_block" = yes ]; then if [ "$line" = '>>>' ]; then - eval "$block" + # Eval template block with error context for debuggability + if ! eval "$block"; then + log ERROR "Template block eval failed in ${CURRENT_TPL:-unknown}" + log ERROR "Block content: $block" + fi is_block=no block='' else @@ -112,8 +116,11 @@ $line" ' } +# Evaluate a single template line (e.g. '<< echo foo') template::_line () { - eval "${1/<< /}" + if ! eval "${1/<< /}"; then + log ERROR "Template line eval failed in ${CURRENT_TPL:-unknown}: $1" + fi } # Sugesting adding a ToC when there are many sections -- cgit v1.2.3