Skip to content

Commit

Permalink
fix: handle file upload and git clone errors
Browse files Browse the repository at this point in the history
  • Loading branch information
keithmanville committed Dec 17, 2024
1 parent 1c4020a commit 8447f70
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/dioptra/restapi/v1/workflows/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,17 @@ def import_resources(

if source_type == ResourceImportSourceTypes.UPLOAD:
bytes = archive_file.stream.read()
with tarfile.open(fileobj=BytesIO(bytes), mode="r:*") as tar:
tar.extractall(path=working_dir, filter="data")
try:
with tarfile.open(fileobj=BytesIO(bytes), mode="r:*") as tar:
tar.extractall(path=working_dir, filter="data")
except Exception as e:
raise DioptraError("Failed to read uploaded tarfile") from e
hash = str(sha256(bytes).hexdigest())
elif source_type == ResourceImportSourceTypes.GIT:
hash = clone_git_repository(git_url, working_dir)
else:
try:
hash = clone_git_repository(git_url, working_dir)
except Exception as e:
raise DioptraError("Failed to clone repository") from e

try:
config = toml.load(working_dir / config_path)
Expand Down

0 comments on commit 8447f70

Please sign in to comment.