Keep <catch> attributes so <catch name="err"> stores the error

The split-tag scanner skipped the attributes on <catch ...>, so
<catch name="err"> never stored the error text and every caught error
read as "". Keep them in Tag::splitKeywords, and have <try> use the
catch tag's name and scope when the try tag itself has no name.

Tested live on barant.com: <catch name> and <try name> both store the
error, including scope="session" and single-quoted attributes; the
catch block still runs; no error leaves the name unset; nested tries
catch body errors at the right level.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Brad ArantandClaude Opus 5.5 committed 2026-11-20 01:51:04 +00:00
1 parent 08462ca996
commit fdcb2b43a9
3 files changed
+19 -2

No files matched your search

+9 -2
View File
@@ -222,13 +222,20 @@ namespace jet {
in.skipWhitespace(); in.skipWhitespace();
if(in.ifNext(">")) if(in.ifNext(">"))
break; break;
else if(in.getTokenExclude("=").getLength() != 0) { else if(coreutils::ZString attrName = in.getTokenExclude("="); attrName.getLength() != 0) {
bool dq = in.ifNext("=\""); bool dq = in.ifNext("=\"");
bool sq = !dq && in.ifNext("='"); bool sq = !dq && in.ifNext("='");
if(dq || sq) { if(dq || sq) {
// Keep the attribute (e.g. <catch name="err">) - it used
// to be skipped and dropped, so <catch name=...> never
// stored the error and every caught error read as "".
char *valueStart = in.getCursor();
while(1) { while(1) {
if(in.ifNext(dq ? "\"" : "'")) char *valueEnd = in.getCursor();
if(in.ifNext(dq ? "\"" : "'")) {
splitKeywords[coreutils::MString(attrName)] = coreutils::MString(coreutils::ZString(valueStart, valueEnd - valueStart));
break; break;
}
in.nextChar(); in.nextChar();
} }
} else { } else {
+6
View File
@@ -139,6 +139,12 @@ namespace jet {
void scanContainerNamed(coreutils::ZString &in, const char *tagName); void scanContainerNamed(coreutils::ZString &in, const char *tagName);
coreutils::MString processModifier(coreutils::MString &value, coreutils::MString &modifier); coreutils::MString processModifier(coreutils::MString &value, coreutils::MString &modifier);
public:
// The split tag's own attributes (raw, unresolved) - e.g. <try>'s
// <catch name="err">, so __trytag can bind the error to that name.
// Last member on purpose: adding it changes no other member's offset.
std::map<coreutils::MString, coreutils::MString> splitKeywords;
}; };
} }
+4
View File
@@ -30,9 +30,13 @@ namespace jet {
// without this a caught mid-render failure would leave partial // without this a caught mid-render failure would leave partial
// try-block output mixed in ahead of the catch block's own. // try-block output mixed in ahead of the catch block's own.
out = ""; out = "";
// <try name="err"> or <catch name="err"> (the usual form).
if(keywordDefined("name")) if(keywordDefined("name"))
storeVariable(resolveKeyword("name"), errorText, storeVariable(resolveKeyword("name"), errorText,
keywordDefined("scope") ? resolveKeyword("scope") : "global"); keywordDefined("scope") ? resolveKeyword("scope") : "global");
else if(splitKeywords.count("name"))
storeVariable(splitKeywords["name"], errorText,
splitKeywords.count("scope") ? coreutils::ZString(splitKeywords["scope"]) : coreutils::ZString("global"));
if(hasContainer2) if(hasContainer2)
processContainer(container2); processContainer(container2);
} }