Skip to content

fix: throw Template::Exception on WHILE loop termination#341

Draft
Koan-Bot wants to merge 1 commit intoabw:masterfrom
atoomic:koan.atoomic/while-exception-type
Draft

fix: throw Template::Exception on WHILE loop termination#341
Koan-Bot wants to merge 1 commit intoabw:masterfrom
atoomic:koan.atoomic/while-exception-type

Conversation

@Koan-Bot
Copy link
Contributor

@Koan-Bot Koan-Bot commented Mar 8, 2026

What

WHILE loop termination now throws a Template::Exception with type while instead of a bare die string.

Why

Previously, a runaway WHILE loop produced a bare die string that couldn't be selectively caught. Template authors had to catch all exceptions with CATCH — there was no way to distinguish a WHILE timeout from other errors. With a typed exception, CATCH while works as expected.

How

Changed the generated code in Directive::while() from die "..." to $context->throw('while', "..."). The $context variable is already available in template scope.

Testing

  • 2 new tests in t/while.t: verify CATCH while catches the exception, and that non-matching CATCH foo does not
  • Full suite passes (2965 tests)

🤖 Generated with Claude Code

…ation

Replace bare die string with $context->throw('while', ...) so template
authors can catch runaway WHILE loops with TRY/CATCH blocks using
a typed exception instead of getting an unrecoverable error.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant