Skip to content

feat: added new exception type to epub conversions #4052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,5 @@ annotated/
.aider*
pcaps
python-output

.vs/
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 0.18.6-dev0

### Enhancements

### Features

### Fixes
- **Improved epub partition errors** EPUB partition will now produce new type of error on unprocessable files.

## 0.18.5

### Enhancements
Expand Down
2 changes: 1 addition & 1 deletion unstructured/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.18.5" # pragma: no cover
__version__ = "0.18.6-dev0" # pragma: no cover
6 changes: 6 additions & 0 deletions unstructured/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ def __init__(self, document_pages: int, pdf_hi_res_max_pages: int):
f"pages={document_pages}, maximum={pdf_hi_res_max_pages}."
)
super().__init__(self.message)


class UnprocessableEpubError(Exception):
"""Error raised when the epub file is not valid."""

pass
10 changes: 10 additions & 0 deletions unstructured/file_utils/file_conversion.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from __future__ import annotations

import os
import re
import tempfile
from typing import IO

from unstructured.errors import UnprocessableEpubError
from unstructured.partition.common.common import exactly_one
from unstructured.utils import requires_dependencies

Expand All @@ -23,6 +25,14 @@ def convert_file_to_text(filename: str, source_format: str, target_format: str)
)
raise FileNotFoundError(msg)
except RuntimeError as err:
err_str = str(err)
if source_format == "epub" and (
"Couldn't extract ePub file" in err_str
or "No entry on path" in err_str
or re.search(r"exitcode ['\"]?64['\"]?", err_str)
):
raise UnprocessableEpubError(f"Invalid EPUB file: {err_str}")

supported_source_formats, _ = pypandoc.get_pandoc_formats()

if source_format == "rtf" and source_format not in supported_source_formats:
Expand Down
Loading