Handle not supported plot type in pptx #1122
Merged
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.
When converting a pptx with an unsupported plot type, in the current version the conversion simply silently fails
This is a simple change that adds a try/catch block and skips the unsupported plot type in case of errors
This is the error you would get with an unmanaged conversion:
'Traceback (most recent call last):\n File "c:\\DevOps\\xxx\\.venv\\Lib\\site-packages\\pptx\\chart\\plot.py", line 236, in PlotFactory\n PlotCls = {\n ~\n ...<8 lines>...\n qn("c:scatterChart"): XyPlot,\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n }[xChart.tag]\n ~^^^^^^^^^^^^\nKeyError: \'{http://schemas.openxmlformats.org/drawingml/2006/chart}pie3DChart\'\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File "c:\\DevOps\\axxx\\.venv\\Lib\\site-packages\\markitdown\\_markitdown.py", line 1715, in _convert\n res = converter.convert(local_path, **_kwargs)\n File "c:\\DevOps\\xxx\\.venv\\Lib\\site-packages\\markitdown\\_markitdown.py", line 903, in convert\n md_content += self._convert_chart_to_markdown(shape.chart)\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^\n File "c:\\DevOps\\xxx\\.venv\\Lib\\site-packages\\markitdown\\_markitdown.py", line 945, in _convert_chart_to_markdown\n category_names = [c.label for c in chart.plots[0].categories]\n ~~~~~~~~~~~^^^\n File "c:\\DevOps\\xxx\\.venv\\Lib\\site-packages\\pptx\\chart\\chart.py", line 277, in __getitem__\n return PlotFactory(xChart, self._chart)\n File "c:\\DevOps\\xxx\\.venv\\Lib\\site-packages\\pptx\\chart\\plot.py", line 248, in PlotFactory\n raise ValueError("unsupported plot type %s" % xChart.tag)\nValueError: unsupported plot type {http://schemas.openxmlformats.org/drawingml/2006/chart}pie3DChart'