Repository navigation
fix: throw HandlebarsCompilerException for #if/#unless with wrong argument count - #678
Merged
Merged
Conversation
…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>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



{{#if}}/{{#unless}}with no argument threw a bareInvalidOperationException: Sequence contains no elementsfromEnumerable.First. That exception isn't aHandlebarsException, so code that catches template errors missed it.Changes
ConditionalBlockAccumulatorContext: a missing argument now throwsHandlebarsCompilerExceptionwith the reader context and the message#if requires exactly one argument/#unless requires exactly one argument(same wording as handlebars.js).{{#if a b}}) throws the same exception type as before, with the same helper-specific message instead ofInvalid argument list for conditional block.{{#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
HandlebarsCompilerExceptioninstead ofInvalidOperationException, and the too-many-arguments message text is different.Tests
Added to
ExceptionTests: missing and extra arguments for#if,#unlessand^if, plus a check that hash arguments still work. The full suite passes.Fixes #674
🤖 Generated with Claude Code
Closes #674