Skip to content

fix: throw HandlebarsCompilerException for #if/#unless with wrong argument count - #678

Merged
stencil-harness[bot] merged 1 commit into
masterfrom
claude/issue-674
Nov 7, 2026
Merged

stencil-harness[bot] merged 1 commit into
masterfrom
claude/issue-674

Conversation

@stencil-harness

Copy link
Copy Markdown
Contributor

{{#if}} / {{#unless}} with no argument threw a bare InvalidOperationException: Sequence contains no elements from Enumerable.First. That exception isn't a HandlebarsException, so code that catches template errors missed it.

Changes

  • ConditionalBlockAccumulatorContext: a missing argument now throws HandlebarsCompilerException with the reader context and the message #if requires exactly one argument / #unless requires exactly one argument (same wording as handlebars.js).
  • The too-many-arguments case ({{#if a b}}) throws the same exception type as before, with the same helper-specific message instead of Invalid argument list for conditional block.
  • Hash arguments ({{#if a includeZero=true}}) are unaffected.

Compatibility

Both cases already failed at compile time, so templates that compiled before still compile and render the same way. Callers will see a change in two places: the no-argument case now throws HandlebarsCompilerException instead of InvalidOperationException, and the too-many-arguments message text is different.

Tests

Added to ExceptionTests: missing and extra arguments for #if, #unless and ^if, plus a check that hash arguments still work. The full suite passes.

Fixes #674

🤖 Generated with Claude Code

Closes #674

…ument count

{{#if}} / {{#unless}} with no argument threw a bare
InvalidOperationException from Enumerable.First. Both the missing- and
extra-argument cases now throw HandlebarsCompilerException with the
reader context and a helper-specific message ("#if requires exactly one
argument"), matching handlebars.js.

Fixes #674

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

sonarqubecloud Bot commented Nov 7, 2026

Copy link
Copy Markdown

@stencil-harness
stencil-harness Bot merged commit fb77ff0 into master Nov 7, 2026
7 checks passed
@stencil-harness
stencil-harness Bot deleted the claude/issue-674 branch November 7, 2026 23:01
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.

{{#if}} / {{#unless}} without an argument throw InvalidOperationException: Sequence contains no elements

1 participant