@@ -165,6 +165,29 @@ def dump(self):
165165 print (f"- { item .file_path } { item .chunk_index } { item .size } " )
166166 print ("--- END ---" )
167167
168+ def log_upload_details_error (self , err : ClientError ):
169+ """Log details about the upload job changes accumulated with ClientError"""
170+ http_code = getattr (err , "http_error" , None )
171+ self .mp .log .error (
172+ f"Push failed with HTTP code { http_code } . "
173+ f"Upload details: { len (self .upload_queue_items )} file chunks, total size { self .total_size } bytes."
174+ )
175+ self .mp .log .error ("Files:" )
176+ for f in self .changes .get_upload_changes ():
177+ path = f .path if f .path else "<unknown>"
178+ size = f .size if f .size else "?"
179+ diff_info = f .get_diff ()
180+ if diff_info :
181+ diff_size = diff_info .size if diff_info .size else "?"
182+ # best-effort: number of geodiff changes (if available)
183+ changes_cnt = self .mp .get_geodiff_changes_count (diff_info .path )
184+ if changes_cnt is None :
185+ self .mp .log .error (f" - { path } , size={ size } , diff_size={ diff_size } , changes=n/a" )
186+ else :
187+ self .mp .log .error (f" - { path } , size={ size } , diff_size={ diff_size } , changes={ changes_cnt } " )
188+ else :
189+ self .mp .log .error (f" - { path } , size={ size } " )
190+
168191 def _submit_item_to_thread (self , item : UploadQueueItem ):
169192 """Upload a single item in the background"""
170193 future = self .executor .submit (_do_upload , item , self )
@@ -404,6 +427,10 @@ def push_project_finalize(job: UploadJob):
404427 if not err .is_retryable_sync ():
405428 # clear the upload chunks cache, as we are getting fatal from server
406429 job .mc .upload_chunks_cache .clear ()
430+ http_code = getattr (err , "http_error" , None )
431+ if http_code in (502 , 504 ):
432+ job .log_upload_details_error (err )
433+ cleanup_tmp_dir (job .mp , job .tmp_dir ) # delete our temporary dir and all its content
407434 job .mp .log .error ("--- push finish failed! " + str (err ))
408435 raise err
409436 elif with_upload_of_files :
@@ -415,25 +442,7 @@ def push_project_finalize(job: UploadJob):
415442 # Log additional metadata on server error 502 or 504 (extended logging only)
416443 http_code = getattr (err , "http_error" , None )
417444 if http_code in (502 , 504 ):
418- job .mp .log .error (
419- f"Push failed with HTTP error { http_code } . "
420- f"Upload details: { len (job .upload_queue_items )} file chunks, total size { job .total_size } bytes."
421- )
422- job .mp .log .error ("Files:" )
423- for f in job .changes .get ("added" , []) + job .changes .get ("updated" , []):
424- path = f .get ("path" , "<unknown>" )
425- size = f .get ("size" , "?" )
426- if "diff" in f :
427- diff_info = f .get ("diff" , {})
428- diff_size = diff_info .get ("size" , "?" )
429- # best-effort: number of geodiff changes (if available)
430- changes_cnt = _geodiff_changes_count (job .mp , diff_info .get ("path" ))
431- if changes_cnt is None :
432- job .mp .log .error (f" - { path } , size={ size } , diff_size={ diff_size } , changes=n/a" )
433- else :
434- job .mp .log .error (f" - { path } , size={ size } , diff_size={ diff_size } , changes={ changes_cnt } " )
435- else :
436- job .mp .log .error (f" - { path } , size={ size } " )
445+ job .log_upload_details_error (err )
437446
438447 # server returns various error messages with filename or something generic
439448 # it would be better if it returned list of failed files (and reasons) whenever possible
@@ -466,25 +475,6 @@ def push_project_finalize(job: UploadJob):
466475 job .mp .log .info ("--- push finished - new project version " + job .server_resp ["version" ])
467476
468477
469- def _geodiff_changes_count (mp : MerginProject , diff_rel_path : str ):
470- """
471- Best-effort: return number of changes in the .gpkg diff (int) or None.
472- Never raises – diagnostics/logging must not fail.
473- """
474-
475- diff_abs = mp .fpath_meta (diff_rel_path )
476- try :
477- return pygeodiff .GeoDiff ().changes_count (diff_abs )
478- except (
479- pygeodiff .GeoDiffLibError ,
480- pygeodiff .GeoDiffLibConflictError ,
481- pygeodiff .GeoDiffLibUnsupportedChangeError ,
482- pygeodiff .GeoDiffLibVersionError ,
483- FileNotFoundError ,
484- ):
485- return None
486-
487-
488478def push_project_cancel (job : UploadJob ):
489479 """
490480 To be called (from main thread) to cancel a job that has uploads in progress.
@@ -499,6 +489,7 @@ def push_project_cancel(job: UploadJob):
499489 if not job .transaction_id :
500490 # If not v2 api endpoint with transaction, nothing to cancel on server
501491 job .mp .log .info ("--- push cancelled" )
492+ cleanup_tmp_dir (job .mp , job .tmp_dir ) # delete our temporary dir and all its content
502493 return
503494 try :
504495 resp_cancel = job .mc .post ("/v1/project/push/cancel/%s" % job .transaction_id )
0 commit comments