Skip to content

Commit cf53d5f

Browse files
committed
fix(cloud-import): surface real error instead of mislabeling snapshot prep
run_add_mutation handles snapshot/body failures itself and returns False, so the broad except only ever catches pre-mutation errors (name resolution, registry read, plan construction). Echo the real exception instead of the old 'Failed to prepare mutation snapshot' label, which hid the cause at DEBUG level.
1 parent b5ebf52 commit cf53d5f

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

‎openkb/cli.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,11 @@ def append_cloud_log() -> None:
698698
return "failed"
699699
except DirtyRollbackError:
700700
raise
701-
except Exception:
702-
click.echo(f" [ERROR] Failed to prepare mutation snapshot for cloud import {doc_id}.")
701+
except Exception as exc:
702+
# run_add_mutation handles snapshot/body failures itself (returns False),
703+
# so this except only catches pre-mutation errors — surface the real cause
704+
# instead of the old misleading "Failed to prepare mutation snapshot" label.
705+
click.echo(f" [ERROR] Cloud import failed for {doc_id}: {exc}")
703706
logger.debug("Cloud import mutation traceback:", exc_info=True)
704707
return "failed"
705708

‎tests/test_add_command.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,27 @@ def test_cloud_import_propagates_dirty_rollback(self, tmp_path):
617617

618618
assert exc_info.value is dirty_error
619619

620+
def test_cloud_import_failure_message_names_real_cause(self, tmp_path, capsys):
621+
"""A non-body failure caught at the outer except (here: name resolution)
622+
must surface the real error, not be mislabeled as 'Failed to prepare
623+
mutation snapshot'. run_add_mutation handles snapshot/body failures
624+
itself and returns False, so the broad except only ever catches
625+
pre-mutation errors that the old label misdescribed."""
626+
from openkb.cli import import_from_pageindex_cloud
627+
628+
kb_dir = self._setup_kb(tmp_path)
629+
cloud = self._cloud_data(doc_name="Cloud-Paper")
630+
631+
with patch("openkb.cli.prepare_cloud_import", return_value=cloud), \
632+
patch("openkb.cli.resolve_doc_name_from_key",
633+
side_effect=RuntimeError("name resolution blew up")), \
634+
patch("openkb.cli._setup_llm_key"):
635+
assert import_from_pageindex_cloud("cloud-1", kb_dir) == "failed"
636+
637+
out = capsys.readouterr().out
638+
assert "Failed to prepare mutation snapshot" not in out
639+
assert "name resolution blew up" in out
640+
620641
def test_cloud_import_keyboard_interrupt_rolls_back_artifacts(self, tmp_path):
621642
import pytest
622643

0 commit comments

Comments
 (0)