summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-01 17:38:05 +0200
committerPaul Buetow <paul@buetow.org>2026-03-01 17:38:05 +0200
commitad91490664d34c121c0efa96441320ea8949233a (patch)
treeab4ffef1af3f9fb10c0bc22aea68172a14359108 /lib
parentfc063aba4822e8e7d9ccc6c721fc2a711298e166 (diff)
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 <noreply@anthropic.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/template.source.sh11
1 files 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