Skip to content

fix: report the real cause when cel-python or tree-sitter fails to import - #582

Open
Marc-cn wants to merge 1 commit into
darnitdevorg:mainfrom
Marc-cn:fix/import-guard-messages
Open

Marc-cn wants to merge 1 commit into
darnitdevorg:mainfrom
Marc-cn:fix/import-guard-messages

Conversation

@Marc-cn

@Marc-cn Marc-cn commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

Two import guards report "not installed" for any ImportError. While working on #573 that pointed at the wrong cause twice:

What was wrong What darnit said
tree-sitter-language-pack 1.6.3 was installed, but its module was missing "tree-sitter-language-pack is not installed"
cel-python was installed; celpy.c7nlib could not import packaging "cel-python not installed. Install with: pip install cel-python"

In both cases the package was installed and the advice was wrong. This keeps the original error text:

  • darnit_baseline/threat_model/parsing.py: the fallback get_language / get_parser raise "tree-sitter-language-pack could not be imported: ".
  • darnit/sieve/cel_evaluator.py: the three guards raise "cel-python could not be imported: ".

Same failures, new messages:

cel-python could not be imported: No module named 'packaging.version'
tree-sitter-language-pack could not be imported: No module named 'tree_sitter_language_pack'

Follow-up to the note in #573 ("Including the original exception text in the message would help. Not changed here.").

Type of Change

  • Bug fix (non-breaking change fixing an issue)
  • New feature (non-breaking change adding functionality)
  • Breaking change (fix or feature causing existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)

Framework Changes Checklist

  • Updated framework spec (docs/architecture/framework-design.md) if behavior changed (message text only)
  • Ran uv run python scripts/validate_sync.py --verbose and it passes

Testing

  • Tests pass locally (uv run pytest tests/ -v): 5139 passed, 26 skipped (main: 5138)

  • Added tests for new functionality (if applicable)

  • Linting passes (uv run ruff check .)

  • New tests/darnit/sieve/test_cel_import_failure.py: makes import celpy fail with a specific error and asserts the raised CELCompilationError carries it and no longer says "not installed". It fails without the fix.

  • The parsing guard has no automated test. Its branch is marked # pragma: no cover, and exercising it means failing a module import and reloading the module inside the test session. I checked it by hand: with tree_sitter_language_pack blocked in sys.modules, the message is "tree-sitter-language-pack could not be imported: import of tree_sitter_language_pack halted; None in sys.modules".

No existing test asserts on the old wording.

AI assistance

  • No AI assistance was used
  • AI assistance was used

Claude Fable 5.1 wrote the changes and drafted this description. I ran every command and checked the results myself. The commit carries an `Assisted-by: Claude:claude-fable-5-1 trailer.

Additional Notes

I only changed the two guards I hit and read. There may be others with the same pattern elsewhere; I did not do a full sweep.

…port

Both import guards said 'not installed' for any ImportError. In darnitdevorg#573 the packages were installed: one release shipped without its module, and the other could not import a dependency. The message and its install advice pointed at the wrong cause.

Say 'could not be imported' and include the original error text.

Signed-off-by: Marc-cn <130138935+Marc-cn@users.noreply.github.com>
Assisted-by: Claude:claude-fable-5-1
@Marc-cn
Marc-cn requested a review from mlieberman85 as a code owner October 10, 2026 16:18
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