MarkItDownException class.
Exception Hierarchy
Exception Classes
MarkItDownException
MarkItDownException
MissingDependencyException
MissingDependencyException
MissingDependencyException
Raised when a converter recognizes a file format but the required optional dependencies are not installed.Inheritance
Inherits fromMarkItDownException.When Raised
This exception is thrown when:- A converter’s
convert()method is called - The converter recognizes the file format
- Required optional dependencies for that format are not installed
This is not necessarily a fatal error. The converter will be skipped, and MarkItDown will try other converters. An error only bubbles up if no suitable converter is found.
Error Message Format
The error message clearly indicates which dependency is missing and provides installation instructions:Example
UnsupportedFormatException
UnsupportedFormatException
UnsupportedFormatException
Raised when no suitable converter was found for the given file.Inheritance
Inherits fromMarkItDownException.When Raised
This exception is thrown when:- MarkItDown has tried all available converters
- None of the converters support the file format
- The file extension or content type is not recognized
Example
FileConversionException
FileConversionException
FileConversionException
Raised when a suitable converter was found, but the conversion process fails.Inheritance
Inherits fromMarkItDownException.Constructor Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
message | Optional[str] | None | Custom error message. If not provided, a message is auto-generated based on attempts. |
attempts | Optional[List[FailedConversionAttempt]] | None | List of failed conversion attempts with details about each failure. |
Attributes
| Attribute | Type | Description |
|---|---|---|
attempts | Optional[List[FailedConversionAttempt]] | List of failed conversion attempts, each containing converter info and exception details. |
When Raised
This exception is thrown when:- A suitable converter was found for the file
- The conversion process started but failed
- The file may be corrupted or have unexpected content
Auto-Generated Error Messages
If no message is provided:- Without attempts:
"File conversion failed." - With attempts: Detailed message listing each failed attempt with converter name and error details
Example
FailedConversionAttempt
FailedConversionAttempt
FailedConversionAttempt
Represents a single failed attempt to convert a file. This is not an exception class, but a data class used byFileConversionException.Constructor Parameters
| Parameter | Type | Description |
|---|---|---|
converter | Any | The converter instance that attempted the conversion. |
exc_info | Optional[tuple] | Exception information tuple (type, value, traceback) from the failed attempt. |
Attributes
| Attribute | Type | Description |
|---|---|---|
converter | Any | The converter instance that attempted the conversion. |
exc_info | Optional[tuple] | Exception information tuple containing details about what went wrong. |
Example
Complete Exception Handling Example
Here’s a comprehensive example showing how to handle all MarkItDown exceptions:Best Practices
Specific Exception Handling
Catch specific exceptions before the base
MarkItDownException to handle different error scenarios appropriately.Check Attempts
When handling
FileConversionException, check the attempts attribute for detailed diagnostic information.Graceful Degradation
Handle
MissingDependencyException gracefully by providing clear installation instructions to users.User Feedback
Use exception messages to provide helpful feedback to users about what went wrong and how to fix it.