Skip to content

Commit

Permalink
add error wrapping to uploader
Browse files Browse the repository at this point in the history
  • Loading branch information
rbiseck3 committed Jan 9, 2025
1 parent b2c14e3 commit 757b329
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from pydantic import BaseModel, Field

from unstructured_ingest.error import (
DestinationConnectionError,
SourceConnectionError,
)
from unstructured_ingest.utils.dep_check import requires_dependencies
Expand Down Expand Up @@ -196,16 +195,18 @@ def precheck(self) -> None:
try:
assert self.connection_config.get_client().current_user.me().active
except Exception as e:
logger.error(f"failed to validate connection: {e}", exc_info=True)
raise DestinationConnectionError(f"failed to validate connection: {e}")
raise self.connection_config.wrap_error(e=e)

def run(self, path: Path, file_data: FileData, **kwargs: Any) -> None:
output_path = os.path.join(
self.upload_config.path, f"{file_data.source_identifiers.filename}.json"
)
with open(path, "rb") as elements_file:
self.connection_config.get_client().files.upload(
file_path=output_path,
contents=elements_file,
overwrite=True,
)
try:
self.connection_config.get_client().files.upload(
file_path=output_path,
contents=elements_file,
overwrite=True,
)
except Exception as e:
raise self.connection_config.wrap_error(e=e)

0 comments on commit 757b329

Please sign in to comment.