fix: capture SCP stderr for better error messages

This commit is contained in:
Claus Lohmar 2026-07-24 09:43:19 +00:00
parent 6e161a6105
commit cd5f31505a

View file

@ -475,7 +475,8 @@ def scp_start(
logger.info("Starting SCP pull: %s%s", remote, dest) logger.info("Starting SCP pull: %s%s", remote, dest)
try: try:
proc = subprocess.Popen(cmd, env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) proc = subprocess.Popen(cmd, env=env, stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE, text=True)
except Exception as exc: except Exception as exc:
return JSONResponse({"phase": "error", "error": f"Failed to start SCP: {exc}"}, status_code=500) return JSONResponse({"phase": "error", "error": f"Failed to start SCP: {exc}"}, status_code=500)
@ -516,11 +517,17 @@ def scp_progress(session_id: str, filename: str):
if poll is not None: if poll is not None:
_active_scp.pop(key, None) _active_scp.pop(key, None)
if poll != 0: if poll != 0:
stderr_output = ""
try:
stderr_output = proc.stderr.read()[:500] if proc.stderr else ""
except Exception:
pass
if dest.exists(): if dest.exists():
dest.unlink(missing_ok=True) dest.unlink(missing_ok=True)
logger.error("SCP pull failed (rc=%d): %s", poll, stderr_output)
return JSONResponse({ return JSONResponse({
"phase": "error", "phase": "error",
"error": f"SCP pull failed (exit code {poll}). Check credentials and remote path.", "error": f"SCP pull failed (exit code {poll}). {stderr_output}",
"file_size_bytes": current_bytes, "file_size_bytes": current_bytes,
}) })
final_bytes = dest.stat().st_size final_bytes = dest.stat().st_size