Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/markitdown/src/markitdown/_markitdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ def _convert(

# Check if the converter will accept the file, and if so, try to convert it
_accepts = False
res: Optional[DocumentConverterResult] = None
try:
_accepts = converter.accepts(file_stream, stream_info, **_kwargs)
except NotImplementedError:
Expand Down
23 changes: 23 additions & 0 deletions packages/markitdown/tests/test_module_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,29 @@ def test_exceptions() -> None:
assert type(exc_info.value.attempts[0].converter).__name__ == "PptxConverter"


def test_converter_failure_does_not_raise_unboundlocalerror() -> None:
class BrokenPdfConverter:
def accepts(self, file_stream, stream_info, **kwargs):
return stream_info.extension == ".pdf"

def convert(self, file_stream, stream_info, **kwargs):
raise RuntimeError("broken converter")

markitdown = MarkItDown(enable_builtins=False, enable_plugins=False)
markitdown.register_converter(BrokenPdfConverter())

with pytest.raises(FileConversionException) as exc_info:
markitdown._convert(
file_stream=io.BytesIO(b"%PDF-broken"),
stream_info_guesses=[
StreamInfo(extension=".pdf", mimetype="application/pdf")
],
)

assert len(exc_info.value.attempts) == 1
assert type(exc_info.value.attempts[0].converter).__name__ == "BrokenPdfConverter"


@pytest.mark.skipif(
skip_exiftool,
reason="do not run if exiftool is not installed",
Expand Down