fix(lib.sh): load_state_json strict treats a missing DB table as unreadable (Issue #71)
A DB without its sessions table (or without both tables) was read as an empty registry in strict mode, so stop closed a registered session row-less and exited 0. Strict mode now fails on any OperationalError; the non-strict reader is unchanged. Refs #71 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a47a4683f3
commit
5f6065344f
2 files changed
+16
-8
No files matched your search
@@ -1592,8 +1592,8 @@ herdr() {
|
||||
# NOTE: Retained as small inline PYEOF block (39 lines) per Plan Rev.2 (Job 98393a97).
|
||||
# Small blocks have minimal overhead and high local cohesion; extraction into lib_py is reserved for large blocks (>200 lines).
|
||||
# `load_state_json strict` (Issue #71) fails (stderr, exit 1) when the YAML or
|
||||
# DB cannot be read, instead of printing {} - for a caller that acts on a
|
||||
# session being absent.
|
||||
# DB cannot be read, a DB table missing included, instead of printing {} - for
|
||||
# a caller that acts on a session being absent.
|
||||
load_state_json() {
|
||||
env_python "$AGENT_SESSIONS_YAML" "MAM_STATE_READ=${1:-}" <<'PYEOF'
|
||||
import os, sys, sqlite3, json, yaml
|
||||
@@ -1610,16 +1610,16 @@ try:
|
||||
row = conn.execute('SELECT data FROM state WHERE id=1').fetchone()
|
||||
if row:
|
||||
d = json.loads(row[0])
|
||||
except sqlite3.OperationalError as e:
|
||||
if strict and 'no such table' not in str(e):
|
||||
except sqlite3.OperationalError:
|
||||
if strict:
|
||||
raise
|
||||
try:
|
||||
cursor = conn.execute('SELECT data FROM sessions')
|
||||
for r in cursor.fetchall():
|
||||
db_sessions.append(json.loads(r[0]))
|
||||
d['herdr_sessions'] = db_sessions
|
||||
except sqlite3.OperationalError as e:
|
||||
if strict and 'no such table' not in str(e):
|
||||
except sqlite3.OperationalError:
|
||||
if strict:
|
||||
raise
|
||||
conn.close()
|
||||
elif os.path.exists(yaml_path):
|
||||
|
||||
Reference in new issue
Block a user