From d0ed74fdf4708e9931d8bc4dc5c711b1e9d444fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menezes?= <77670471+menezesandre@users.noreply.github.com> Date: Fri, 28 Feb 2025 07:11:27 +0000 Subject: [PATCH] Fix UnboundLocalError in MarkItDown._convert (#1038) Initialize `res` at the beginning of `_convert`. If the first converter raises an exception, then the `res` variable was not initialized and we got an error when checking `if res is not None` --- packages/markitdown/src/markitdown/_markitdown.py | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/markitdown/src/markitdown/_markitdown.py b/packages/markitdown/src/markitdown/_markitdown.py index 297f554..7c8d006 100644 --- a/packages/markitdown/src/markitdown/_markitdown.py +++ b/packages/markitdown/src/markitdown/_markitdown.py @@ -312,6 +312,7 @@ class MarkItDown: def _convert( self, local_path: str, extensions: List[Union[str, None]], **kwargs ) -> DocumentConverterResult: + res: Union[None, DocumentConverterResult] = None error_trace = "" # Create a copy of the page_converters list, sorted by priority.