Skip to content

Commit 37e04ff

Browse files
[nightshift] Narrow bare except Exception in fray FileQueue (#3618)
> *Seed scattered wide—* > *bare catches swallow the bugs,* > *narrowed, light breaks through.* - **`file.py`**: Replaced two bare `except Exception:` blocks with `except OSError:` in `FileQueue.pop()` and `FileQueue._recover_expired_leases()`. The broad catches silently swallowed programming errors (TypeError, ValueError, etc.) that should propagate—only filesystem errors (OSError and subclasses like FileNotFoundError) are expected here. - **`http.py`**: Moved `import socket` from inside `get_client_host()` to module level. It's a stdlib import, not an optional dependency guard, so it belongs at the top per coding standards §1.1. Both issues are explicitly flagged as deprecated patterns in `docs/dev-guide/coding-standards.md` §8.2.
1 parent e6ee448 commit 37e04ff

2 files changed

Lines changed: 3 additions & 4 deletions

File tree

lib/fray/src/fray/v1/queue/file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def pop(self, lease_timeout: float = 60.0) -> Lease[T] | None:
8181
try:
8282
files = sorted(self.fs.ls(str(self.pending_dir), detail=False))
8383
files = [f for f in files if f.rstrip("/") != str(self.pending_dir).rstrip("/")]
84-
except Exception:
84+
except OSError:
8585
return None
8686

8787
for file_path in files:
@@ -106,7 +106,7 @@ def _recover_expired_leases(self) -> None:
106106
"""Check processing directory for expired leases and move them back to pending."""
107107
try:
108108
files = self.fs.ls(str(self.processing_dir), detail=False)
109-
except Exception:
109+
except OSError:
110110
return
111111

112112
now = time.time()

lib/fray/src/fray/v1/queue/http.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import logging
99
import pickle
10+
import socket
1011
import threading
1112
import time
1213
from typing import Any
@@ -115,8 +116,6 @@ def get_client_host(self) -> str:
115116
Returns the actual IP address using default route.
116117
"""
117118
if self.host == "0.0.0.0":
118-
import socket
119-
120119
# Get the IP address that clients should use by checking default route
121120
try:
122121
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

0 commit comments

Comments
 (0)