debug: add state.json path logging to diagnose save failure
This commit is contained in:
+50
-2
@@ -84,8 +84,15 @@ def save_state(state):
|
|||||||
sp = _state_path()
|
sp = _state_path()
|
||||||
state["updated_at"] = datetime.now().isoformat()
|
state["updated_at"] = datetime.now().isoformat()
|
||||||
_LAST_STATE = state
|
_LAST_STATE = state
|
||||||
with open(sp, "w", encoding="utf-8") as f:
|
try:
|
||||||
json.dump(state, f, indent=2, ensure_ascii=False)
|
with open(sp, "w", encoding="utf-8") as f:
|
||||||
|
json.dump(state, f, indent=2, ensure_ascii=False)
|
||||||
|
except Exception as e:
|
||||||
|
# Fallback: stderr
|
||||||
|
import sys
|
||||||
|
print(f"[STATE ERROR] Не удалось сохранить state в {sp}: {e}", file=sys.stderr)
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc(file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
def set_stage(stage, **kwargs):
|
def set_stage(stage, **kwargs):
|
||||||
@@ -94,6 +101,47 @@ def set_stage(stage, **kwargs):
|
|||||||
for k, v in kwargs.items():
|
for k, v in kwargs.items():
|
||||||
state[k] = v
|
state[k] = v
|
||||||
save_state(state)
|
save_state(state)
|
||||||
|
return state
|
||||||
|
|
||||||
|
|
||||||
|
def mark_completed(step):
|
||||||
|
state = load_state()
|
||||||
|
if step not in state["completed_steps"]:
|
||||||
|
state["completed_steps"].append(step)
|
||||||
|
save_state(state)
|
||||||
|
|
||||||
|
|
||||||
|
def is_completed(step):
|
||||||
|
return step in load_state().get("completed_steps", [])
|
||||||
|
|
||||||
|
|
||||||
|
def set_error(step, stdout, stderr, suggestion=""):
|
||||||
|
state = load_state()
|
||||||
|
state["paused"] = True
|
||||||
|
state["last_error"] = {
|
||||||
|
"step": step,
|
||||||
|
"timestamp": datetime.now().isoformat(),
|
||||||
|
"stdout": stdout,
|
||||||
|
"stderr": stderr,
|
||||||
|
"suggestion": suggestion,
|
||||||
|
}
|
||||||
|
save_state(state)
|
||||||
|
|
||||||
|
|
||||||
|
def reset_state(mode=None):
|
||||||
|
"""Сбрасывает состояние для нового запуска (source, target или полностью)."""
|
||||||
|
global _LAST_STATE
|
||||||
|
state = load_state()
|
||||||
|
state["stage"] = "INIT"
|
||||||
|
state["mode"] = mode
|
||||||
|
state["completed_steps"] = []
|
||||||
|
state["interrupted_at"] = None
|
||||||
|
state["resumable_hint"] = None
|
||||||
|
state["last_error"] = None
|
||||||
|
state["paused"] = False
|
||||||
|
state["updated_at"] = datetime.now().isoformat()
|
||||||
|
_LAST_STATE = state
|
||||||
|
save_state(state)
|
||||||
|
|
||||||
|
|
||||||
def mark_completed(step):
|
def mark_completed(step):
|
||||||
|
|||||||
Reference in New Issue
Block a user