Refactor step 4: narrow broad except Exception catches
Replaced 28 bare `except Exception` catches across 8 files with specific exception types reflecting the actual failure modes: - JSON file reads → (OSError, json.JSONDecodeError) - datetime parsing → ValueError - base64 decoding → ValueError - YAML parsing → (OSError, yaml.YAMLError); import moved above try - GeoJSON coord extraction → (TypeError, IndexError, AttributeError) - Startup temp-file cleanup → OSError - Single JSON line parsing (SSE batch) → json.JSONDecodeError Kept broad catches only where intentional: - Background thread top-level guards (tasks.py, admin.py) with log.exception - SSE stream generator tops (strava.py, garmin.py, uploads.py) - Per-item batch loops that must not abort the whole operation - Explicitly non-fatal post-upload merge steps with log.warning
This commit is contained in:
@@ -151,7 +151,7 @@ async def me_delete_account(
|
||||
from bincio.render.cli import _write_root_manifest
|
||||
try:
|
||||
_write_root_manifest(deps._get_data_dir())
|
||||
except Exception:
|
||||
except (OSError, json.JSONDecodeError):
|
||||
pass
|
||||
|
||||
resp = JSONResponse({"ok": True})
|
||||
@@ -214,7 +214,7 @@ async def me_get_strava_credentials(bincio_session: str | None = Cookie(default=
|
||||
if cid and csec:
|
||||
has_user_creds = True
|
||||
client_id_hint = cid
|
||||
except Exception:
|
||||
except (OSError, json.JSONDecodeError):
|
||||
pass
|
||||
return JSONResponse({
|
||||
"has_user_creds": has_user_creds,
|
||||
@@ -242,7 +242,7 @@ async def me_set_strava_credentials(
|
||||
try:
|
||||
existing = json.loads(creds_path.read_text(encoding="utf-8"))
|
||||
csec = str(existing.get("client_secret", "")).strip()
|
||||
except Exception:
|
||||
except (OSError, json.JSONDecodeError):
|
||||
pass
|
||||
if not csec:
|
||||
raise HTTPException(400, "client_secret is required (no existing secret to preserve)")
|
||||
@@ -255,7 +255,7 @@ async def me_set_strava_credentials(
|
||||
old_cid = str(json.loads(creds_path.read_text(encoding="utf-8")).get("client_id", "")).strip()
|
||||
if old_cid and old_cid != cid:
|
||||
token_path.unlink(missing_ok=True)
|
||||
except Exception:
|
||||
except (OSError, json.JSONDecodeError):
|
||||
pass
|
||||
|
||||
creds_path.write_text(
|
||||
|
||||
Reference in New Issue
Block a user