1+ """Module for the default file uploader implementation."""
2+
13import logging
24from pathlib import Path
3- import traceback
45import urllib
56import tempfile
67import asyncio
@@ -78,7 +79,7 @@ async def upload_file(
7879 file : UploadFile ,
7980 ) -> None :
8081 """
81- Uploads a source file for content extraction.
82+ Upload a source file for content extraction.
8283
8384 Parameters
8485 ----------
@@ -109,7 +110,7 @@ async def upload_file(
109110 raise HTTPException (status_code = status .HTTP_400_BAD_REQUEST , detail = str (e ))
110111 except Exception as e :
111112 self ._key_value_store .upsert (source_name , Status .ERROR )
112- logger .error ("Error while uploading %s = %s " , source_name , str ( e ) )
113+ logger .exception ("Error while uploading %s" , source_name )
113114 raise HTTPException (status_code = status .HTTP_500_INTERNAL_SERVER_ERROR , detail = str (e ))
114115
115116 def _log_task_exception (self , task : asyncio .Task ) -> None :
@@ -124,19 +125,16 @@ def _log_task_exception(self, task: asyncio.Task) -> None:
124125 if task .done () and not task .cancelled ():
125126 try :
126127 task .result () # This will raise the exception if one occurred
127- except Exception as e :
128- logger .error ("Background task failed with exception: %s" , str (e ))
129- logger .debug ("Background task exception traceback: %s" , traceback .format_exc ())
128+ except Exception :
129+ logger .exception ("Background task failed with exception" )
130130
131131 def _prune_background_tasks (self ) -> None :
132- """
133- Remove completed background tasks from the list.
134- """
132+ """Remove completed background tasks from the list."""
135133 self ._background_tasks = [task for task in self ._background_tasks if not task .done ()]
136134
137135 def _check_if_already_in_processing (self , source_name : str ) -> None :
138136 """
139- Checks if the source is already in processing state.
137+ Check if the source is already in processing state.
140138
141139 Parameters
142140 ----------
@@ -196,9 +194,9 @@ async def _handle_source_upload(
196194 await asyncio .to_thread (self ._rag_api .upload_information_piece , rag_information_pieces )
197195 self ._key_value_store .upsert (source_name , Status .READY )
198196 logger .info ("Source uploaded successfully: %s" , source_name )
199- except Exception as e :
197+ except Exception :
200198 self ._key_value_store .upsert (source_name , Status .ERROR )
201- logger .error ("Error while uploading %s = %s " , source_name , str ( e ) )
199+ logger .exception ("Error while uploading %s" , source_name )
202200
203201 def _add_file_url (self , file_name : str , base_url : str , chunked_documents : list [Document ]):
204202 document_url = f"{ base_url .rstrip ('/' )} /document_reference/{ urllib .parse .quote_plus (file_name )} "
@@ -229,6 +227,6 @@ async def _asave_new_document(
229227
230228 self ._file_service .upload_file (Path (temp_file_path ), filename )
231229 return filename
232- except Exception as e :
233- logger .error ("Error during document saving: %s %s" , e , traceback . format_exc () )
230+ except Exception :
231+ logger .exception ("Error during document saving" )
234232 self ._key_value_store .upsert (source_name , Status .ERROR )
0 commit comments