Skip to content

fix: return failure for Hindsight import errors#42

Merged
AxDSan merged 4 commits into
AxDSan:mainfrom
kohai-ut:fix/import-hindsight-error-exit
May 11, 2026
Merged

fix: return failure for Hindsight import errors#42
AxDSan merged 4 commits into
AxDSan:mainfrom
kohai-ut:fix/import-hindsight-error-exit

Conversation

@kohai-ut
Copy link
Copy Markdown
Contributor

@kohai-ut kohai-ut commented May 8, 2026

Summary

mnemosyne import-hindsight now exits non-zero when the import result contains errors.

Before this change, a failed Hindsight import could print a JSON result with an errors array while still returning exit code 0. 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:

mnemosyne import-hindsight /tmp/missing-export.json

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 1 when result.errors is 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 to import_from_hindsight() and printed the returned ImporterResult, but never translated importer errors into a process failure:

result = import_from_hindsight(...)
print(result.to_json())

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:

print(result.to_json())
if result.errors:
    raise SystemExit(1)

No importer behavior or JSON schema is changed.

Tests

Added a subprocess CLI regression test covering a missing Hindsight export file:

  • invokes the public CLI boundary via python -m mnemosyne.cli import-hindsight ...
  • isolates HOME and MNEMOSYNE_DATA_DIR
  • verifies non-zero exit status
  • verifies stderr remains empty
  • verifies stdout remains parseable JSON with provider/errors
  • verifies no traceback is printed

Verification

.venv/bin/python -m pytest tests/test_cli_errors.py::test_import_hindsight_errors_return_nonzero_exit -q
# 1 passed

.venv/bin/python -m pytest tests/test_cli_errors.py tests/test_hermes_hindsight_cli.py tests/test_importers/test_hindsight.py -q
# 13 passed

.venv/bin/python -m pytest -q
# 464 passed, 1 warning

 git diff --check
# clean

Non-goals

  • Does not change ImporterResult semantics.
  • Does not change successful import behavior.
  • Does not convert the command to human-readable stderr errors; JSON output is preserved for automation.

@AxDSan AxDSan merged commit 1311c85 into AxDSan:main May 11, 2026
5 checks passed
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