Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: raise UploadErrors for images and annotations #266

Merged
merged 6 commits into from
Aug 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions roboflow/core/project.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
import json
import os
import re
import sys
import time
import warnings
Expand Down Expand Up @@ -493,6 +494,8 @@ def single_upload(
)
image_id = uploaded_image["id"]
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 @@ -514,6 +517,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 @@ -546,6 +551,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: str = None,
Expand Down