Repository navigation
fix(extract): fail loudly when no transactions are extracted - #1452
Conversation
`extract` printed "Extracted 0 transactions" and returned Ok regardless of the result, so a garbage / wrong-type / empty file yielded exit 0. A scripted `extract … >> ledger.beancount` then silently appended nothing (only a nonexistent path exited non-zero). Bail with an actionable message (likely causes + what to try) when the result is empty, before writing output, so the exit code is non-zero. Regression test asserts a non-importable file exits non-zero with the explanation. Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR updates the rledger extract CLI to stop silently succeeding when an input file produces an empty extraction result, which helps prevent scripts from appending nothing to a ledger without noticing.
Changes:
- Make
extractreturn a non-zero exit code with an actionable error message when the extraction result is empty. - Add a CLI regression test asserting non-importable input fails with an explanatory message.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
crates/rustledger/src/cmd/extract_cmd/mod.rs |
Adds an empty-result guard that bails with guidance instead of exiting 0 after extracting nothing. |
crates/rustledger/tests/cli_commands_test.rs |
Adds a regression test verifying extract exits non-zero and explains the empty extraction case. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Resolve cli_commands_test.rs conflict: keep both the #11 broken-pipe test (from main) and the new #18 empty-extract test. - Count EXTRACTED transactions right after importer.extract() and bail only when that is zero — before duplicate filtering (--existing) or --balance augmentation, which could otherwise mask the cause (all duplicates, or a lone balance directive). - Base the "Extracted N transactions" count on Directive::Transaction values rather than directives.len(). - Use OsStr-safe .arg(file.path()) in the regression test. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Addressed both findings: the empty-result check now counts EXTRACTED transactions right after |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
📊 Benchmark Results
vs main branch (2026-06-20)
What do these numbers mean?
|
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
What
extractprintedExtracted 0 transactionsand exited 0 regardless of the result, so a garbage / wrong-type / empty file silently produced nothing:A scripted
extract … >> ledger.beancounttherefore appends nothing silently on a malformed or wrong-path-but-existing file (only a nonexistent path exited non-zero).How
Bail with an actionable message when the result is empty (before writing output), so the exit code is non-zero:
Verify
A valid CSV still extracts normally (regression guarded). Regression test
test_extract_empty_result_exits_nonzeroasserts a non-importable file exits non-zero with the explanation.🤖 Generated with Claude Code