refactor(errors): replace silent exception handling in console and server

This commit is contained in:
somew1nd committed 2026-09-01 17:57:15 -07:00
1 parent 41deb48005
commit c76c9bb7e8
20 files changed
+267 -107

No files matched your search

+8 -3
View File
@@ -13,11 +13,13 @@
# limitations under the License.
from contextlib import contextmanager
import logging
from pathlib import Path
import sqlite3
from artemis.config import DB_PATH
logger = logging.getLogger(__name__)
_initialized_dbs = set()
@@ -33,14 +35,17 @@ def get_db(db_path: Path | None = None) -> sqlite3.Connection:
StorageManager(db_path=path, base_trace_dir=path.parent)
_initialized_dbs.add(path_key)
except Exception:
pass
except (ImportError, OSError, sqlite3.Error) as exc:
# Schema bootstrap is best-effort here; queries against a missing
# schema will surface their own errors, but log the root cause.
logger.warning("Schema bootstrap failed for %s: %s", path, exc)
conn = sqlite3.connect(path, timeout=10.0)
conn.row_factory = sqlite3.Row
try:
conn.execute("PRAGMA journal_mode=WAL")
conn.execute("PRAGMA busy_timeout=10000")
except Exception:
except sqlite3.Error:
# Optional performance PRAGMAs; the connection works without them.
pass
return conn
@@ -12,11 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
import time
from typing import Any
from artemis.runtime import trace_store
logger = logging.getLogger(__name__)
try:
from admin_console.database.connection import db_session
except ImportError:
@@ -317,8 +320,15 @@ class SessionRepository:
"failed",
error="Process terminated prior to server startup.",
)
except Exception:
pass
except OSError as exc:
# read_status itself never raises; this guards the
# lock/write side of update_trace_status.
logger.warning(
"Could not mark trace %s failed during orphan "
"reconciliation: %s",
row["session_id"],
exc,
)
conn.commit()
return count
except Exception:
@@ -106,7 +106,8 @@ class StepRepository:
if isinstance(payload_raw, str):
try:
payload_obj = json.loads(payload_raw)
except Exception:
except (ValueError, TypeError):
# Non-JSON payload: the isinstance(dict) guard below bails out.
pass
if not isinstance(payload_obj, dict):
return 0, 0, 0
@@ -175,7 +176,8 @@ class StepRepository:
if isinstance(payload_raw, str):
try:
payload_obj = json.loads(payload_raw)
except Exception:
except (ValueError, TypeError):
# Non-JSON payload: the isinstance(dict) guard below bails out.
pass
if not isinstance(payload_obj, dict):
@@ -308,7 +310,8 @@ class StepRepository:
if step_dict.get(json_col):
try:
step_dict[json_col] = json.loads(step_dict[json_col])
except Exception:
except (ValueError, TypeError):
# Non-JSON column value: keep the raw string.
pass
# If post_image_name is identical to pre_image_name, normalize to None
@@ -471,7 +474,8 @@ class StepRepository:
p_raw_th.append(str(th_text).strip())
elif thr["type"] == "thinking" and th_text:
p_nat_th.append(str(th_text).strip())
except Exception:
except (ValueError, TypeError, AttributeError):
# Unparseable or non-dict thinking payload: skip it.
pass
virtual_step = {
@@ -52,7 +52,8 @@ class TraceRepository:
if row_dict.get("payload"):
try:
row_dict["payload"] = json.loads(row_dict["payload"])
except Exception:
except (ValueError, TypeError):
# Non-JSON payload: keep the raw string for display.
pass
nodes[row_dict["trace_id"]] = {**row_dict, "children": []}
@@ -94,7 +95,8 @@ class TraceRepository:
if row_dict.get("payload"):
try:
row_dict["payload"] = json.loads(row_dict["payload"])
except Exception:
except (ValueError, TypeError):
# Non-JSON payload: keep the raw string for display.
pass
nodes[row_dict["trace_id"]] = {**row_dict, "children": []}