Files
kumomta/crates/kumod/test_http_build_errors.lua
T
Wez Furlong 35e29643b5 further improve inject template errors
Let's give the templates more human readable names so that the error
messaging naturally has more context.
2026-01-07 11:24:20 +00:00

46 lines
1.3 KiB
Lua

local kumo = require 'kumo'
local utils = require 'policy-extras.policy_utils'
local ok, msg_or_err = pcall(kumo.api.inject.build_v1, {
envelope_sender = 'no-reply@example.com',
recipients = {
{ email = 'user@example.com', name = 'John Smith' },
},
content = {
text_body = 'Hello {{ First Name }},\nThis is the second line',
},
})
assert(not ok)
msg_or_err = tostring(msg_or_err)
assert(
utils.starts_with(
msg_or_err,
"failed parsing field 'content.text_body' as template: syntax error: unexpected identifier, expected end of variable block (in template 'text_body.txt' line 1: 'Hello {{ First Name }},')\n"
),
msg_or_err
)
local ok, msg_or_err = pcall(kumo.api.inject.build_v1, {
envelope_sender = 'no-reply@example.com',
recipients = {
{ email = 'user@example.com', name = 'John Smith' },
},
content = {
text_body = 'Hello {{ Name }},\nThis is the second line',
headers = {
['X-Woot'] = '{{ First Name }}',
},
},
})
assert(not ok)
msg_or_err = tostring(msg_or_err)
assert(
utils.starts_with(
msg_or_err,
"failed parsing field headers['X-Woot'] as template: syntax error: unexpected identifier, expected end of variable block (in template 'headers[X-Woot]' line 1: '{{ First Name }}')\n"
),
msg_or_err
)