diff --git a/roboflow/core/project.py b/roboflow/core/project.py index 79f01152..34f01475 100644 --- a/roboflow/core/project.py +++ b/roboflow/core/project.py @@ -1,6 +1,7 @@ import datetime import json import os +import re import sys import time import warnings @@ -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: @@ -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: @@ -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"\'", "") + temp_str = temp_str.replace('"', r"\"") + temp_str = temp_str.replace("'", '"') + dict_part = temp_str.replace("", "'") + 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,