Skip to content

fix: raise ExpressionError for an unknown expression type - #460

Merged
malthe merged 2 commits into
malthe:masterfrom
rahul05ranjan:fix/expr-type-unknown-expression
Nov 13, 2026
Merged

malthe merged 2 commits into
malthe:masterfrom
rahul05ranjan:fix/expr-type-unknown-expression

Conversation

@rahul05ranjan

Copy link
Copy Markdown
Contributor

Fixes #458.

Problem

ExpressionParser.__call__ raised a bare LookupError("Unknown expression type: 'nocall'.") for any unknown or misspelled expression type, with no source location — an internal-looking exception for what is a template language error.

Fix

Raise the documented chameleon.exc.ExpressionError instead, passing the full expression source so the error renders with the expression and its location like other expression errors:

chameleon.exc.ExpressionError: Unknown expression type: 'nocall'.

 - String:     "nocall: some_var"

The message text is unchanged.

Verification

New regression test test_unknown_expression_type_raises_expression_error fails on un-fixed HEAD (a7d8f8f) with LookupError and passes with this patch:

python3 -m pytest src/chameleon/tests -q

on CPython 3.13 (system Python, Raspberry Pi OS): 234 passed, 5 failed — the 5 failures are the pre-existing loader/egg/wheel packaging tests that also fail on un-fixed HEAD with byte-identical output (they need wheel/egg installation machinery this host doesn't have).

Co-authored-by: rahul05ranjan 11793455+rahul05ranjan@users.noreply.github.com

rahul05ranjan and others added 2 commits November 12, 2026 22:27
An unknown or misspelled expression type (e.g. nocall: or strng:)
raised a bare LookupError with no source location. Raise the
documented ExpressionError so the error is reported with the template
source instead.

Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
@malthe
malthe merged commit 44f26bc into malthe:master Nov 13, 2026
25 checks passed
@rahul05ranjan

Copy link
Copy Markdown
Contributor Author

Thank you for the merge! 🎉

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 43378129287

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage increased (+0.05%) to 92.859%

Details

  • Coverage increased (+0.05%) from the base build.
  • Patch coverage: 7 of 7 lines across 2 files are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 4225
Covered Lines: 3992
Line Coverage: 94.49%
Relevant Branches: 830
Covered Branches: 702
Branch Coverage: 84.58%
Branches in Coverage %: Yes
Coverage Strength: 1.89 hits per line

💛 - Coveralls

@rahul05ranjan

This comment was marked as off-topic.

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.

Unknown expression type raises bare LookupError instead of ExpressionError

3 participants