fix(storage): harden portable path diagnostics

This commit is contained in:
2026-07-11 21:25:03 +02:00
parent eacb139e22
commit 7f3f6f7ce7
4 changed files with 100 additions and 6 deletions
+12 -4
View File
@@ -6,6 +6,7 @@ from pathlib import Path
from typing import Any
import typer
import yaml
from tht.cli.config_cmd import CONFIG_OPT
from tht.config import ConfigError, load_config
@@ -17,7 +18,14 @@ def _emit(payload: dict[str, Any], as_json: bool) -> None:
typer.echo(json.dumps(payload, sort_keys=True))
return
for component, result in payload["components"].items():
typer.echo(f"{component}: {result['status']}")
detail = ""
if result["status"] == "error":
detail = f" - {result['message']}"
elif component == "data_root" and result["status"] == "warning":
detail = " - set THT_DATA_ROOT to enable portable storage"
elif component == "workspace_paths" and result["status"] == "warning":
detail = " - absolute legacy roots: " + ", ".join(result["legacy_absolute"])
typer.echo(f"{component}: {result['status']}{detail}")
def doctor(
@@ -32,11 +40,11 @@ def doctor(
}
try:
cfg = load_config(config)
except ConfigError as exc:
path_error = "outside workspace root" in str(exc)
except (ConfigError, yaml.YAMLError, OSError) as exc:
path_error = isinstance(exc, ConfigError) and "outside workspace" in str(exc)
target = "workspace_paths" if path_error else "config"
# Validation errors can contain Pydantic input excerpts, including credentials.
message = str(exc) if path_error else "configuration is invalid"
message = str(exc) if path_error else "configuration is invalid or unreadable"
components[target] = {"status": "error", "message": message}
payload = {"ok": False, "components": components}
_emit(payload, as_json)