fix: return failure for Hindsight import errors#42
Merged
Conversation
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.
Summary
mnemosyne import-hindsightnow exits non-zero when the import result contains errors.Before this change, a failed Hindsight import could print a JSON result with an
errorsarray while still returning exit code0. That makes the command look successful to shells, CI jobs, cron jobs, and other automation even though no import actually succeeded.User-visible behavior
Example failure case before this PR:
Output included an error:
{ "provider": "hindsight", "total": 0, "imported": 0, "errors": [ "Hindsight import failed: [Errno 2] No such file or directory: '/tmp/missing-export.json'" ] }…but the process exited with status
0.After this PR, the command still prints the structured JSON result, but exits with status
1whenresult.errorsis non-empty.Why preserve JSON output?
The command appears to be machine-readable by design: it prints
ImporterResult.to_json()rather than a human-only message. This PR preserves that behavior so callers can continue parsing the result payload, while also making shell-level success/failure correct.Root cause
cmd_import_hindsight()delegated toimport_from_hindsight()and printed the returnedImporterResult, but never translated importer errors into a process failure:The importer already records failures in
result.errors; the CLI just needed to reflect that in its exit status.Implementation
The fix is intentionally small:
No importer behavior or JSON schema is changed.
Tests
Added a subprocess CLI regression test covering a missing Hindsight export file:
python -m mnemosyne.cli import-hindsight ...HOMEandMNEMOSYNE_DATA_DIRVerification
Non-goals
ImporterResultsemantics.