2
2
import json
3
3
import mimetypes
4
4
import os
5
+ import re
5
6
import sys
6
7
import time
7
8
import warnings
@@ -510,6 +511,8 @@ def single_upload(
510
511
)
511
512
image_id = uploaded_image ["id" ] # type: ignore[index]
512
513
upload_retry_attempts = retry .retries
514
+ except rfapi .UploadError as e :
515
+ raise RuntimeError (f"Error uploading image: { self ._parse_upload_error (e )} " )
513
516
except BaseException as e :
514
517
uploaded_image = {"error" : e }
515
518
finally :
@@ -531,6 +534,8 @@ def single_upload(
531
534
annotation_labelmap = annotation_labelmap ,
532
535
overwrite = annotation_overwrite ,
533
536
)
537
+ except rfapi .UploadError as e :
538
+ raise RuntimeError (f"Error uploading annotation: { self ._parse_upload_error (e )} " )
534
539
except BaseException as e :
535
540
uploaded_annotation = {"error" : e }
536
541
finally :
@@ -563,6 +568,20 @@ def _annotation_params(self, annotation_path):
563
568
)
564
569
return annotation_name , annotation_string
565
570
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
+
566
585
def search (
567
586
self ,
568
587
like_image : Optional [str ] = None ,
0 commit comments