Repository navigation
fix(loader): actionable error for module-name Python plugin refs - #1435
Merged
Merged
Conversation
A Python plugin declared by module name (beancount's `plugin "pkg.mod"`) is unsupported by design — only file-path references load (see `discover_module_source`). It routes into the Python-plugin branch (the name contains a dot), runs, and fails inside `execute_module`, surfacing as `E8002: Python plugin 'pkg.mod' execution failed: Python plugin module not found: pkg.mod` — doubly misleading, reading as a venv/PYTHONPATH problem the user cannot fix. Detect the bare-module-name case in the error path and emit an actionable `E8004` instead: name the unsupported form and point at the file path, resolving it via system Python (`suggest_module_path`) when possible, else a generic hint that also notes the sandbox cannot see the host venv (the plugin must be self-contained). This also unifies the code with the parallel unknown-plugin branch (both `E8004`). The existing `suggest_module_path`/`E8004` hint was unreachable for real module names because they always contain a dot and were diverted into the Python branch first. Closes #1432 (Gap 1). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
Improves rustledger’s loader UX for Python plugins referenced by module name (plugin "pkg.mod"), which are unsupported by design, by emitting a clearer, actionable diagnostic instead of surfacing a misleading runtime “execution failed / module not found” error.
Changes:
- Updates Python plugin failure handling to detect bare module-name references and emit an actionable
E8004suggesting file-path usage (optionally resolving a path via system Python). - Keeps the existing
E8002behavior for genuine Python plugin execution failures (non-module refs). - Adds a regression test ensuring module-name refs produce an actionable message and do not contain the confusing “execution failed” wrapper.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/rustledger-loader/src/process.rs | Adds module-name detection in the Python-plugin error path and emits E8004 with a file-path-based remediation message. |
| crates/rustledger-loader/tests/loader_test.rs | Adds a regression test asserting the new actionable error message for unsupported module-name plugin references. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
📊 Benchmark Results
vs main branch (2026-06-19)
What do these numbers mean?
|
Gaps 2-3 of #1432. Document that: - Built-in names resolve to the native Rust plugin regardless of the `beancount.plugins.` prefix (so `plugin "beancount.plugins.auto_accounts"` is unchanged), but a custom Python plugin must be referenced by file path — the module-name form is rejected. - Python plugins run in a CPython-WASI sandbox that never mounts the host venv / site-packages, so they must be self-contained (stdlib + the bundled beancount compat shim); anything heavier needs a native Rust plugin. Adds a "Referencing a Python Plugin" + "Plugin Sandbox" section to docs/reference/plugins.md and a file-path note to docs/migration/from-beancount.md (clarifying that the existing auto_accounts example works because it resolves to a native plugin, not Python). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Follow-up to the review on #1435. Instead of running the plugin and relabeling the failure by name-shape, detect a bare module-name reference *before* invoking the runtime: - Correctness (#1): the old error-path relabel discarded the real error `e` for any dotted/non-.py name — masking genuine failures such as a corrupt runtime download (`PythonRuntime::new()` fails before module discovery). Now module names are rejected up front, so the `Err(e)` arm only fires for real plugin files and surfaces `e` verbatim (E8002). - Altitude (#2): no runtime is downloaded/compiled (and no "10-100x slower" warning printed) for a request that is rejectable from the name alone. - Reuse/consistency (#3): both E8004 sites now share `module_ref_message`, so the "not supported by module name; reference the file directly" guidance is identical everywhere. - Discriminator (#4): one `is_python_module_name` helper using `eq_ignore_ascii_case`, not the pre-lowercased `ext` (fixes a latent case-sensitivity coupling). - Docs (#5): document E8002/E8004/E8005 in docs/reference/errors.md. - Cleanup (#6,#7): static example path (drops the dead `unwrap_or` and the `./.py` trailing-dot edge); drop the redundant `is_python_available()` guard (`suggest_module_path` already handles a missing interpreter). fmt + clippy (-D warnings, python-plugins) clean; loader suite 64/64. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ests Addresses the Copilot review note: is_python_module_name checked only std::path::MAIN_SEPARATOR (`\` on Windows), so a forward-slash file ref like "plugins/foo" could be misclassified as a module name there. Check both `/` and the platform separator. Adds direct unit tests for is_python_module_name (module vs .py vs path-separated vs existing-file, case-insensitive ext) and module_ref_message (both the resolved-path and fallback branches — also covering the line codecov flagged). Co-Authored-By: Claude Opus 4.8 <[email protected]>
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.
Implements Gap 1 of #1432: a Python plugin referenced by module name (beancount's
plugin "pkg.mod") now produces an actionable error pointing at the file-path requirement, instead of a misleading "module not found".Problem
Module-name references are unsupported by design — only file paths load (
discover_module_source). But a name likebeancount.plugins.auto_accountscontains a dot, so it routes into the Python-plugin branch, spins up the runtime, and fails insideexecute_module, surfacing as:Doubly confusing — "execution failed" and "module not found" — so users (reasonably) suspect a venv/PYTHONPATH problem rather than an unsupported declaration form. The existing
suggest_module_path()+E8004hint was unreachable for real module names, because they always contain a dot and get diverted into the Python branch before reaching it.Fix
In the Python-plugin error path, detect the bare-module-name case (
ext != "py"and no path separator) and emit an actionable E8004:Python plugin "pkg.mod" is not supported by module name; reference the file directly: plugin "/abs/path/pkg/mod.py"This also unifies the error code with the parallel unknown-plugin branch (both
E8004).Tests
test_python_module_plugin_error_is_actionable(gated onpython-plugins): uses an unresolvable module name for a deterministic message; asserts it contains "not supported by module name" + "reference the file directly" and does not contain "execution failed".test_python_module_plugin_reports_error.Verification
cargo fmt --checkclean ·cargo clippy --features python-plugins -- -D warningsclean · fullloader_testsuite 64/64 pass.Scope
This is Gap 1 only. Gaps 2-3 (document the file-path + self-contained-sandbox model in
docs/reference/plugins.mdanddocs/migration/from-beancount.md) remain open under #1432.