Skip to content

Commit 6dfea66

Browse files
deeenesclaude
andcommitted
Detect non-Parquet server responses (502, 404, HTML error pages)
When the API returns an error page instead of Parquet data, the client now detects this by checking the PAR1 magic bytes before parsing, and raises a clear OmniPathAPIError instead of a cryptic Polars error. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 65f2c8e commit 6dfea66

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

omnipath_client/_response.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,25 @@ def _read_parquet(
7777
# Build the order: requested backend first, then the rest
7878
order = [backend] + [b for b in _BACKEND_ORDER if b != backend]
7979

80+
# Check if the source file is actually Parquet
81+
# (HTTP errors return HTML/text that can't be parsed)
82+
if isinstance(source, (str, Path)):
83+
try:
84+
with open(source, 'rb') as _f:
85+
header = _f.read(4)
86+
if header != b'PAR1':
87+
# Read the content for the error message
88+
_f.seek(0)
89+
text_content = _f.read(500).decode('utf-8', errors='replace')
90+
from omnipath_client._errors import OmniPathAPIError
91+
raise OmniPathAPIError(
92+
f'Server returned non-Parquet response '
93+
f'(likely an error page or the API is down). '
94+
f'Content: {text_content[:200]}'
95+
)
96+
except (OSError, PermissionError):
97+
pass
98+
8099
for name in order:
81100
reader = _PARQUET_READERS.get(name)
82101

0 commit comments

Comments
 (0)