Skip to content

Commit 1083a06

Browse files
authored
Merge pull request #266 from caiquejjx/fix/raise-upload-errors
fix: raise UploadErrors for images and annotations
2 parents 3367958 + 5033c10 commit 1083a06

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

roboflow/core/project.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import mimetypes
44
import os
5+
import re
56
import sys
67
import time
78
import warnings
@@ -510,6 +511,8 @@ def single_upload(
510511
)
511512
image_id = uploaded_image["id"] # type: ignore[index]
512513
upload_retry_attempts = retry.retries
514+
except rfapi.UploadError as e:
515+
raise RuntimeError(f"Error uploading image: {self._parse_upload_error(e)}")
513516
except BaseException as e:
514517
uploaded_image = {"error": e}
515518
finally:
@@ -531,6 +534,8 @@ def single_upload(
531534
annotation_labelmap=annotation_labelmap,
532535
overwrite=annotation_overwrite,
533536
)
537+
except rfapi.UploadError as e:
538+
raise RuntimeError(f"Error uploading annotation: {self._parse_upload_error(e)}")
534539
except BaseException as e:
535540
uploaded_annotation = {"error": e}
536541
finally:
@@ -563,6 +568,20 @@ def _annotation_params(self, annotation_path):
563568
)
564569
return annotation_name, annotation_string
565570

571+
def _parse_upload_error(self, error: rfapi.UploadError) -> str:
572+
dict_part = str(error).split(": ", 2)[2]
573+
dict_part = dict_part.replace("True", "true")
574+
dict_part = dict_part.replace("False", "false")
575+
dict_part = dict_part.replace("None", "null")
576+
if re.search(r"'\w+':", dict_part):
577+
temp_str = dict_part.replace(r"\'", "<PLACEHOLDER>")
578+
temp_str = temp_str.replace('"', r"\"")
579+
temp_str = temp_str.replace("'", '"')
580+
dict_part = temp_str.replace("<PLACEHOLDER>", "'")
581+
parsed_dict: dict = json.loads(dict_part)
582+
message = parsed_dict.get("message")
583+
return message or str(parsed_dict)
584+
566585
def search(
567586
self,
568587
like_image: Optional[str] = None,

0 commit comments

Comments
 (0)