@@ -56,6 +56,7 @@ def upload_cached_file(
5656 obj_type : str ,
5757 file_path : pydantic .FilePath ,
5858 id_mapping : dict [str , str ],
59+ throw_exceptions : bool ,
5960 retry_failed_uploads : bool ,
6061 lock : threading .Lock ,
6162) -> None :
@@ -71,6 +72,10 @@ def upload_cached_file(
7172 The path to the cached file to upload
7273 id_mapping : dict[str, str]
7374 A mapping of offline to online object IDs
75+ throw_exceptions : bool
76+ Whether to throw exceptions, or just log them
77+ retry_failed_uploads : bool
78+ Whether to retry failed uploads or ignore them
7479 lock : threading.Lock
7580 A lock to prevent multiple threads accessing the id mapping directory at once
7681 """
@@ -83,7 +88,10 @@ def upload_cached_file(
8388
8489 try :
8590 _instance_class = getattr (simvue .api .objects , _exact_type )
86- except AttributeError :
91+ except AttributeError as error :
92+ if throw_exceptions :
93+ raise error
94+
8795 _logger .error (f"Attempt to initialise unknown type '{ _exact_type } '" )
8896 _log_upload_failed (file_path )
8997 return
@@ -109,11 +117,13 @@ def upload_cached_file(
109117 _new_id = obj_for_upload .id
110118
111119 except Exception as error :
112- if "status 409" in error . args [ 0 ] :
120+ if "status 409" in str ( error ) :
113121 return
122+ if throw_exceptions :
123+ raise error
114124
115125 _logger .error (
116- f"Error while committing '{ _instance_class .__name__ } ': { error . args [ 0 ] } "
126+ f"Error while committing '{ _instance_class .__name__ } ': { str ( error ) } "
117127 )
118128 _log_upload_failed (file_path )
119129 return
@@ -182,6 +192,7 @@ def sender(
182192 max_workers : int = 5 ,
183193 threading_threshold : int = 10 ,
184194 objects_to_upload : list [str ] = UPLOAD_ORDER ,
195+ throw_exceptions : bool = False ,
185196 retry_failed_uploads : bool = False ,
186197) -> dict [str , str ]:
187198 """Send data from a local cache directory to the Simvue server.
@@ -196,6 +207,8 @@ def sender(
196207 The number of cached files above which threading will be used
197208 objects_to_upload : list[str]
198209 Types of objects to upload, by default uploads all types of objects present in cache
210+ throw_exceptions : bool, optional
211+ Whether to throw exceptions as they are encountered in the sender, default is False (exceptions will be logged)
199212 retry_failed_uploads : bool, optional
200213 Whether to retry sending objects which previously failed, by default False
201214
@@ -238,6 +251,7 @@ def sender(
238251 obj_type = _obj_type ,
239252 file_path = file_path ,
240253 id_mapping = _id_mapping ,
254+ throw_exceptions = throw_exceptions ,
241255 retry_failed_uploads = retry_failed_uploads ,
242256 lock = _lock ,
243257 )
@@ -251,11 +265,15 @@ def sender(
251265 obj_type = _obj_type ,
252266 file_path = file_path ,
253267 id_mapping = _id_mapping ,
268+ throw_exceptions = throw_exceptions ,
254269 retry_failed_uploads = retry_failed_uploads ,
255270 lock = _lock ,
256271 ),
257272 _offline_files ,
258273 )
274+ # This will raise any exceptions encountered during sending
275+ for result in _results :
276+ pass
259277
260278 # Send heartbeats
261279 _headers : dict [str , str ] = {
0 commit comments