mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
fix(backend/copilot): narrow exception handling in _infer_format_from_workspace
Replace bare `except Exception` catch-all with specific exceptions (ValueError, FileNotFoundError, OSError, PermissionError, AttributeError, TypeError) so unexpected programming errors (e.g. KeyError, RuntimeError) propagate instead of being silently swallowed as a None return. Addresses autogpt-reviewer comments #2930931556 and #2930341488.
This commit is contained in:
@@ -355,16 +355,19 @@ async def _infer_format_from_workspace(
|
||||
# Try MIME type first, then filename extension.
|
||||
mime = (info.mime_type or "").split(";", 1)[0].strip().lower()
|
||||
return MIME_TO_FORMAT.get(mime) or infer_format_from_uri(info.name)
|
||||
except (ValueError, FileNotFoundError, OSError, PermissionError):
|
||||
except (
|
||||
ValueError,
|
||||
FileNotFoundError,
|
||||
OSError,
|
||||
PermissionError,
|
||||
AttributeError,
|
||||
TypeError,
|
||||
):
|
||||
# Expected failures: bad URI, missing file, permission denied, or
|
||||
# workspace manager returning unexpected types. Propagate anything
|
||||
# else (e.g. programming errors) so they don't get silently swallowed.
|
||||
logger.debug("workspace metadata lookup failed for %s", uri, exc_info=True)
|
||||
return None
|
||||
except Exception:
|
||||
logger.warning(
|
||||
"unexpected error during workspace metadata lookup for %s",
|
||||
uri,
|
||||
exc_info=True,
|
||||
)
|
||||
return None
|
||||
|
||||
|
||||
def _is_tabular(parsed: Any) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user