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:
Zamil Majdy
2026-03-15 22:43:29 +07:00
parent 72b40f03bd
commit d10ae1f392

View File

@@ -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: