Skip to content

Commit 314a85a

Browse files
committed
cli/add(fix[path-privacy]): redact invalid config errors
why: add_repo raised exception logs with absolute config paths when the existing file wasn't a mapping. what: - reuse display_config_path in the TypeError handler so logs show ~/.vcspull.yaml instead of /home/... - add regression test forcing a list-based config and asserting the log contains the PrivatePath value
1 parent f909904 commit 314a85a

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/vcspull/cli/add.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ def add_repo(
400400
except TypeError:
401401
log.exception(
402402
"Config file %s is not a valid YAML dictionary.",
403-
config_file_path,
403+
display_config_path,
404404
)
405405
return
406406
except Exception:

tests/cli/test_add.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,32 @@ def test_add_repo_creates_new_file(
325325
assert "newrepo" in config["~/"]
326326

327327

328+
def test_add_repo_invalid_config_logs_private_path(
329+
user_path: pathlib.Path,
330+
caplog: pytest.LogCaptureFixture,
331+
) -> None:
332+
"""Errors for invalid configs should report redacted paths."""
333+
config_file = user_path / ".vcspull.yaml"
334+
config_file.write_text("- repo: url\n", encoding="utf-8")
335+
336+
repo_dir = user_path / "projects" / "demo"
337+
repo_dir.mkdir(parents=True, exist_ok=True)
338+
339+
caplog.set_level(logging.ERROR)
340+
341+
add_repo(
342+
name="demo",
343+
url="git+https://github.com/example/demo.git",
344+
config_file_path_str=str(config_file),
345+
path=str(repo_dir),
346+
workspace_root_path=None,
347+
dry_run=True,
348+
)
349+
350+
expected_path = str(PrivatePath(config_file))
351+
assert expected_path in caplog.text
352+
353+
328354
class AddDuplicateMergeFixture(t.NamedTuple):
329355
"""Fixture describing duplicate merge toggles for add_repo."""
330356

0 commit comments

Comments
 (0)