Skip to content

Raise SDK specific Jinja errors on syntax error#798

Merged
ogenstad merged 1 commit intostablefrom
pog-raise-custom-errors
Feb 5, 2026
Merged

Raise SDK specific Jinja errors on syntax error#798
ogenstad merged 1 commit intostablefrom
pog-raise-custom-errors

Conversation

@ogenstad
Copy link
Contributor

@ogenstad ogenstad commented Feb 4, 2026

Related to opsmill/infrahub#8311, we want the SDK to raise our own Jinja2 errors when there are syntax errors in user submitted templates. Then Infrahub could look for those errors specifically.

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling for template syntax errors with accurate line number reporting for easier debugging.
    • Standardized error messages for template-related issues.
  • Tests

    • Added comprehensive test coverage for template syntax error scenarios to ensure reliable error reporting.

@coderabbitai
Copy link

coderabbitai bot commented Feb 4, 2026

Walkthrough

The changes implement standardized error handling for Jinja2 template syntax errors. In infrahub_sdk/template/__init__.py, env.parse(template_source) calls in the get_variables and validate functions are wrapped in try/except blocks to catch jinja2.TemplateSyntaxError. When caught, these errors are delegated to _raise_template_syntax_error, which raises a JinjaTemplateSyntaxError with adjusted filename and line number information for file-based templates. Corresponding test coverage is added in tests/unit/sdk/test_template.py with a test data structure and two parametrized test functions validating error messages and line numbers across multiple syntax error scenarios.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Raise SDK specific Jinja errors on syntax error' directly and accurately summarizes the main change: implementing SDK-specific error types for Jinja syntax errors.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages
Copy link

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 01f0435
Status: ✅  Deploy successful!
Preview URL: https://c0f71c64.infrahub-sdk-python.pages.dev
Branch Preview URL: https://pog-raise-custom-errors.infrahub-sdk-python.pages.dev

View logs

@codecov
Copy link

codecov bot commented Feb 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@            Coverage Diff             @@
##           stable     #798      +/-   ##
==========================================
- Coverage   80.36%   80.35%   -0.01%     
==========================================
  Files         115      115              
  Lines        9865     9871       +6     
  Branches     1504     1504              
==========================================
+ Hits         7928     7932       +4     
- Misses       1415     1416       +1     
- Partials      522      523       +1     
Flag Coverage Δ
integration-tests 41.39% <0.00%> (-0.09%) ⬇️
python-3.10 51.39% <100.00%> (+<0.01%) ⬆️
python-3.11 51.39% <100.00%> (+<0.01%) ⬆️
python-3.12 51.39% <100.00%> (+<0.01%) ⬆️
python-3.13 51.39% <100.00%> (+0.02%) ⬆️
python-3.14 53.04% <100.00%> (+0.02%) ⬆️
python-filler-3.12 24.06% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
infrahub_sdk/template/__init__.py 95.55% <100.00%> (+0.20%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ogenstad ogenstad marked this pull request as ready for review February 5, 2026 13:04
@ogenstad ogenstad requested a review from a team as a code owner February 5, 2026 13:04
@ogenstad ogenstad merged commit ef9b1ca into stable Feb 5, 2026
21 checks passed
@ogenstad ogenstad deleted the pog-raise-custom-errors branch February 5, 2026 16:06
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.

2 participants