fix(backend): catch binary parser exceptions (BadZipFile, KeyError, TypeError)

openpyxl.InvalidFileException and zipfile.BadZipFile extend Exception
directly (not ValueError/OSError), so corrupt xlsx files would escape
the narrowed exception handlers in both parse_file_content and
_expand_bare_ref. Add KeyError (covers ArrowKeyError, OptionError),
TypeError (covers ArrowTypeError), and zipfile.BadZipFile to both
catch clauses.
This commit is contained in:
Zamil Majdy
2026-03-13 22:42:29 +07:00
parent d48eb12d50
commit 7b866a9f22
2 changed files with 8 additions and 0 deletions

View File

@@ -38,6 +38,7 @@ import logging
import os
import re
import tomllib
import zipfile
from dataclasses import dataclass
from typing import Any
@@ -451,6 +452,9 @@ async def _expand_bare_ref(
UnicodeDecodeError,
ImportError,
OSError,
KeyError,
TypeError,
zipfile.BadZipFile,
) as exc:
raise FileRefExpansionError(f"Failed to parse {fmt} file: {exc}") from exc
# Normalize bytes fallback to str so tools never

View File

@@ -31,6 +31,7 @@ import io
import json
import logging
import tomllib
import zipfile
from collections.abc import Callable
# posixpath.splitext handles forward-slash URI paths correctly on all platforms,
@@ -262,6 +263,9 @@ def parse_file_content(content: str | bytes, fmt: str, *, strict: bool = False)
UnicodeDecodeError,
ImportError,
OSError,
KeyError,
TypeError,
zipfile.BadZipFile,
):
if strict:
raise