summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2025-11-13 14:43:26 -0500
committerBen Sima <ben@bsima.me>2025-11-13 14:43:26 -0500
commit55f676da16691c7eb23f1ffcb3b589dc3842b274 (patch)
tree98afaf46f17ff3c01bece44bf412390808539587
parent81c46826005a60018c2a4f31675ba1f5eff1c7d8 (diff)
Replace bare exception catches with specific exceptions
- Replace Exception with httpx.HTTPError, httpx.TimeoutException, re.error in extract_og_metadata - Replace Exception with ValueError, KeyError in auth verification - Replace Exception with httpx errors and ValueError in submit_article - Replace Exception with ValueError, KeyError, AttributeError in RSS feed generation - Replace Exception with ValueError, KeyError in cancel/retry/delete job handlers Improves error handling specificity and removes BLE001 linter suppressions. Amp-Thread-ID: https://ampcode.com/threads/T-8edacbeb-b343-49ca-b524-1c999272acb6 Co-authored-by: Amp <amp@ampcode.com>
-rw-r--r--.tasks/tasks.jsonl2
-rw-r--r--Biz/PodcastItLater/Admin.py4
-rw-r--r--Biz/PodcastItLater/Web.py11
3 files changed, 9 insertions, 8 deletions
diff --git a/.tasks/tasks.jsonl b/.tasks/tasks.jsonl
index 9e1fec6..50a23f4 100644
--- a/.tasks/tasks.jsonl
+++ b/.tasks/tasks.jsonl
@@ -49,7 +49,7 @@
{"taskCreatedAt":"2025-11-13T19:38:08.01779309Z","taskDependencies":[],"taskId":"t-1f9RIzd","taskNamespace":null,"taskParent":null,"taskStatus":"Open","taskTitle":"Account Management Page","taskType":"Epic","taskUpdatedAt":"2025-11-13T19:38:08.01779309Z"}
{"taskCreatedAt":"2025-11-13T19:38:08.176692694Z","taskDependencies":[],"taskId":"t-1f9SnU7","taskNamespace":null,"taskParent":null,"taskStatus":"Open","taskTitle":"Queue Status Improvements","taskType":"Epic","taskUpdatedAt":"2025-11-13T19:38:08.176692694Z"}
{"taskCreatedAt":"2025-11-13T19:38:08.37344762Z","taskDependencies":[],"taskId":"t-1f9Td4U","taskNamespace":null,"taskParent":null,"taskStatus":"Open","taskTitle":"Navbar Styling Cleanup","taskType":"Epic","taskUpdatedAt":"2025-11-13T19:38:08.37344762Z"}
-{"taskCreatedAt":"2025-11-13T19:38:32.95559213Z","taskDependencies":[],"taskId":"t-1fbym1M","taskNamespace":null,"taskParent":"t-1f9QP23","taskStatus":"Open","taskTitle":"Remove BLE001 noqa for bare Exception catches - use specific exceptions","taskType":"WorkTask","taskUpdatedAt":"2025-11-13T19:38:32.95559213Z"}
+{"taskCreatedAt":"2025-11-13T19:38:32.95559213Z","taskDependencies":[],"taskId":"t-1fbym1M","taskNamespace":null,"taskParent":"t-1f9QP23","taskStatus":"InProgress","taskTitle":"Remove BLE001 noqa for bare Exception catches - use specific exceptions","taskType":"WorkTask","taskUpdatedAt":"2025-11-13T19:42:23.431401671Z"}
{"taskCreatedAt":"2025-11-13T19:38:33.139120541Z","taskDependencies":[],"taskId":"t-1fbz7LV","taskNamespace":null,"taskParent":"t-1f9QP23","taskStatus":"Open","taskTitle":"Fix PLR0913 violations - refactor functions with too many parameters","taskType":"WorkTask","taskUpdatedAt":"2025-11-13T19:38:33.139120541Z"}
{"taskCreatedAt":"2025-11-13T19:38:33.309222802Z","taskDependencies":[],"taskId":"t-1fbzQ1v","taskNamespace":null,"taskParent":"t-1f9QP23","taskStatus":"Open","taskTitle":"Extract format_duration utility to shared UI or Core module (used only in Web.py)","taskType":"WorkTask","taskUpdatedAt":"2025-11-13T19:38:33.309222802Z"}
{"taskCreatedAt":"2025-11-13T19:38:33.491331064Z","taskDependencies":[],"taskId":"t-1fbABoD","taskNamespace":null,"taskParent":"t-1f9QP23","taskStatus":"Open","taskTitle":"Extract extract_og_metadata and send_magic_link to Core module for reusability","taskType":"WorkTask","taskUpdatedAt":"2025-11-13T19:38:33.491331064Z"}
diff --git a/Biz/PodcastItLater/Admin.py b/Biz/PodcastItLater/Admin.py
index 4920b39..6892234 100644
--- a/Biz/PodcastItLater/Admin.py
+++ b/Biz/PodcastItLater/Admin.py
@@ -615,7 +615,7 @@ def retry_queue_item(request: Request, job_id: int) -> Response:
status_code=200,
headers={"HX-Redirect": "/admin"},
)
- except Exception as e: # noqa: BLE001
+ except (ValueError, KeyError) as e:
return Response(
f"Error retrying job: {e!s}",
status_code=500,
@@ -643,7 +643,7 @@ def delete_queue_item(request: Request, job_id: int) -> Response:
status_code=200,
headers={"HX-Redirect": "/admin"},
)
- except Exception as e: # noqa: BLE001
+ except (ValueError, KeyError) as e:
return Response(
f"Error deleting job: {e!s}",
status_code=500,
diff --git a/Biz/PodcastItLater/Web.py b/Biz/PodcastItLater/Web.py
index 27b75dd..3524be8 100644
--- a/Biz/PodcastItLater/Web.py
+++ b/Biz/PodcastItLater/Web.py
@@ -159,7 +159,7 @@ def extract_og_metadata(url: str) -> tuple[str | None, str | None]:
if author:
author = html_module.unescape(author)
- except Exception as e: # noqa: BLE001
+ except (httpx.HTTPError, httpx.TimeoutException, re.error) as e:
logger.warning("Failed to extract metadata from %s: %s", url, e)
return None, None
else:
@@ -1113,7 +1113,8 @@ def verify_magic_link(request: Request) -> Response:
return RedirectResponse("/")
- except Exception: # noqa: BLE001
+ except (ValueError, KeyError):
+ # Token is invalid or expired
return RedirectResponse("/?error=expired_link")
@@ -1288,7 +1289,7 @@ def submit_article(request: Request, data: FormData) -> html.div: # noqa: PLR09
classes=["alert", "alert-success"],
)
- except Exception as e: # noqa: BLE001
+ except (httpx.HTTPError, httpx.TimeoutException, ValueError) as e:
return html.div(
html.i(classes=["bi", "bi-exclamation-triangle", "me-2"]),
f"Error: {e!s}",
@@ -1343,7 +1344,7 @@ def rss_feed(request: Request, token: str) -> Response: # noqa: ARG001
media_type="application/rss+xml; charset=utf-8",
)
- except Exception as e: # noqa: BLE001
+ except (ValueError, KeyError, AttributeError) as e:
return Response(f"Error generating feed: {e}", status_code=500)
@@ -1473,7 +1474,7 @@ def cancel_queue_item(request: Request, job_id: int) -> Response:
status_code=200,
headers={"HX-Trigger": "queue-updated"},
)
- except Exception as e: # noqa: BLE001
+ except (ValueError, KeyError) as e:
return Response(
f"Error cancelling job: {e!s}",
status_code=500,