debug: add state.json path logging to diagnose save failure
This commit is contained in:
@@ -84,8 +84,15 @@ def save_state(state):
|
||||
sp = _state_path()
|
||||
state["updated_at"] = datetime.now().isoformat()
|
||||
_LAST_STATE = state
|
||||
with open(sp, "w", encoding="utf-8") as f:
|
||||
json.dump(state, f, indent=2, ensure_ascii=False)
|
||||
try:
|
||||
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):
|
||||
@@ -94,6 +101,47 @@ def set_stage(stage, **kwargs):
|
||||
for k, v in kwargs.items():
|
||||
state[k] = v
|
||||
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):
|
||||
|
||||
Reference in New Issue
Block a user