mirror of
https://github.com/Unstructured-IO/unstructured.git
synced 2025-07-24 17:41:15 +00:00

The CustomError that we use to wrap custom ingest errors inherits from BaseException rather than Exception (as we should, per specification [here](https://docs.python.org/3/library/exceptions.html#BaseException)). This resulted in exceptions not properly raising as expected. This PR changes the inheritance which resolves the known issue. Additionally, our base definition for get_file on IngestDoc was wrapped with SourceConnectionError, however this must be explicitly decorating each subclass definition in order to function. This PR does that. ## Testing Some unit test coverage was added for the error wrapping class, however this wasn't properly recreating the issue we are seeing when running ingest tests. To recreate that issue one can intentionally raise an exception in the [partition_file](https://github.com/Unstructured-IO/unstructured/blob/main/unstructured/ingest/interfaces.py#L214C9-L214C23) definition and then run any ingest test. Prior to this change: the code and logs suggest that everything ran without exception, but the partitioned output was not generated (as a result the test will fail without any clues as to what went wrong). With this update, the expected custom partition error, error message, and stack trace will be visible. --------- Co-authored-by: Ahmet Melek <39141206+ahmetmeleq@users.noreply.github.com>
30 lines
858 B
Python
30 lines
858 B
Python
import traceback
|
|
|
|
import pytest
|
|
|
|
from unstructured.ingest.error import (
|
|
DestinationConnectionError,
|
|
PartitionError,
|
|
SourceConnectionError,
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("error_class", "exception_type", "error_message"),
|
|
[
|
|
(SourceConnectionError, ValueError, "Simulated connection error"),
|
|
(DestinationConnectionError, RuntimeError, "Simulated connection error"),
|
|
(PartitionError, FileNotFoundError, "Simulated partition error"),
|
|
],
|
|
)
|
|
def test_custom_error_decorator(error_class, exception_type, error_message):
|
|
@error_class.wrap
|
|
def simulate_error():
|
|
raise exception_type(error_message)
|
|
|
|
with pytest.raises(error_class) as context:
|
|
simulate_error()
|
|
|
|
expected_error_string = error_class.error_string.format(error_message)
|
|
assert str(context.value) == expected_error_string
|