fix(pptx): return a placeholder when a chart read fails instead of None - #2294
Open
Guillermo Dols (gdols) wants to merge 1 commit into
Open
fix(pptx): return a placeholder when a chart read fails instead of None#2294Guillermo Dols (gdols) wants to merge 1 commit into
Guillermo Dols (gdols) wants to merge 1 commit into
Conversation
_convert_chart_to_markdown returns "[unsupported chart]" from both of its exception handlers, but the ValueError handler returned it only when the message contained "unsupported plot type". Every other ValueError reached the end of that handler and fell off the function, so the method returned None. The caller concatenates the result onto md_content unguarded, so the None raises TypeError: can only concatenate str (not "NoneType") to str. That is caught by MarkItDown._convert and re-raised as FileConversionException, so a single unreadable chart loses the whole presentation rather than one shape. Both handlers produced the same string, so collapsing them into one except Exception preserves the output and removes the None path. The same defect is present in the copy carried by markitdown-ocr.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PptxConverter._convert_chart_to_markdowncan returnNone, and the caller concatenates the result straight ontomd_content, so one unreadable chart fails the conversion of the entire presentation.The path
Both exception handlers in that method produce the same
[unsupported chart]placeholder, but theValueErrorone is guarded by a message check:A
ValueErrorcarrying any other message falls out of the handler, the function ends, andNonecomes back. The call site does not check it:MarkItDown._convertcatches the resultingTypeErrorand, with no other converter accepting a.pptx, re-raises it asFileConversionException:So the failure mode is not a chart rendered badly — it is the whole deck lost, including every slide that converted fine.
The change
Since both handlers returned the same string, the
ValueErrorbranch was only ever narrowing which errors got handled. Collapsing them into a singleexcept Exceptionkeeps the output identical for the case that already worked and removes the path that returnsNone.markitdown-ocrcarries its own copy of this method with the same defect, so it gets the same fix.Tests
packages/markitdown/tests/test_pptx_chart_errors.py:ValueErroras well as forunsupported plot type(parametrized);Two of the four fail on
mainand all four pass with this change. The rest of the suite is unaffected andblackreports no changes.Note
This does not overlap #2264, which reworks the body of the
tryfor scatter and bubble series; the handler tail this touches is untouched there.