mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user