Skip to content

Commit

Permalink
Merge pull request #266 from caiquejjx/fix/raise-upload-errors
Browse files Browse the repository at this point in the history
fix: raise UploadErrors for images and annotations
  • Loading branch information
LinasKo authored Aug 15, 2024
2 parents 3367958 + 5033c10 commit 1083a06
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions roboflow/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import mimetypes
import os
import re
import sys
import time
import warnings
Expand Down Expand Up @@ -510,6 +511,8 @@ def single_upload(
)
image_id = uploaded_image["id"] # type: ignore[index]
upload_retry_attempts = retry.retries
except rfapi.UploadError as e:
raise RuntimeError(f"Error uploading image: {self._parse_upload_error(e)}")
except BaseException as e:
uploaded_image = {"error": e}
finally:
Expand All @@ -531,6 +534,8 @@ def single_upload(
annotation_labelmap=annotation_labelmap,
overwrite=annotation_overwrite,
)
except rfapi.UploadError as e:
raise RuntimeError(f"Error uploading annotation: {self._parse_upload_error(e)}")
except BaseException as e:
uploaded_annotation = {"error": e}
finally:
Expand Down Expand Up @@ -563,6 +568,20 @@ def _annotation_params(self, annotation_path):
)
return annotation_name, annotation_string

def _parse_upload_error(self, error: rfapi.UploadError) -> str:
dict_part = str(error).split(": ", 2)[2]
dict_part = dict_part.replace("True", "true")
dict_part = dict_part.replace("False", "false")
dict_part = dict_part.replace("None", "null")
if re.search(r"'\w+':", dict_part):
temp_str = dict_part.replace(r"\'", "<PLACEHOLDER>")
temp_str = temp_str.replace('"', r"\"")
temp_str = temp_str.replace("'", '"')
dict_part = temp_str.replace("<PLACEHOLDER>", "'")
parsed_dict: dict = json.loads(dict_part)
message = parsed_dict.get("message")
return message or str(parsed_dict)

def search(
self,
like_image: Optional[str] = None,
Expand Down

0 comments on commit 1083a06

Please sign in to comment.