fix: replace bare except with except Exception (#22473)
Replace bare except clauses with except Exception to follow Python best practices and avoid catching unexpected system exceptions like KeyboardInterrupt and SystemExit.
This commit is contained in:
@@ -41,7 +41,7 @@ class ExternalDocumentLoader(BaseLoader):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
headers["X-Filename"] = quote(os.path.basename(self.file_path))
|
headers["X-Filename"] = quote(os.path.basename(self.file_path))
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if self.user is not None:
|
if self.user is not None:
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ class MinerULoader:
|
|||||||
try:
|
try:
|
||||||
error_data = e.response.json()
|
error_data = e.response.json()
|
||||||
error_detail += f" - {error_data}"
|
error_detail += f" - {error_data}"
|
||||||
except:
|
except Exception:
|
||||||
error_detail += f" - {e.response.text}"
|
error_detail += f" - {e.response.text}"
|
||||||
raise HTTPException(status.HTTP_400_BAD_REQUEST, detail=error_detail)
|
raise HTTPException(status.HTTP_400_BAD_REQUEST, detail=error_detail)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -252,7 +252,7 @@ class MinerULoader:
|
|||||||
try:
|
try:
|
||||||
error_data = e.response.json()
|
error_data = e.response.json()
|
||||||
error_detail += f" - {error_data.get('msg', error_data)}"
|
error_detail += f" - {error_data.get('msg', error_data)}"
|
||||||
except:
|
except Exception:
|
||||||
error_detail += f" - {e.response.text}"
|
error_detail += f" - {e.response.text}"
|
||||||
raise HTTPException(status.HTTP_400_BAD_REQUEST, detail=error_detail)
|
raise HTTPException(status.HTTP_400_BAD_REQUEST, detail=error_detail)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -355,7 +355,7 @@ class MinerULoader:
|
|||||||
try:
|
try:
|
||||||
error_data = e.response.json()
|
error_data = e.response.json()
|
||||||
error_detail += f" - {error_data.get('msg', error_data)}"
|
error_detail += f" - {error_data.get('msg', error_data)}"
|
||||||
except:
|
except Exception:
|
||||||
error_detail += f" - {e.response.text}"
|
error_detail += f" - {e.response.text}"
|
||||||
raise HTTPException(status.HTTP_400_BAD_REQUEST, detail=error_detail)
|
raise HTTPException(status.HTTP_400_BAD_REQUEST, detail=error_detail)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ class ChromaClient(VectorDBBase):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
except:
|
except Exception:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get(self, collection_name: str) -> Optional[GetResult]:
|
def get(self, collection_name: str) -> Optional[GetResult]:
|
||||||
|
|||||||
@@ -1095,7 +1095,7 @@ async def send_chat_message_event_by_id(
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
except:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ async def set_tool_servers_config(
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
request.app.state.oauth_client_manager.remove_client(client_key)
|
request.app.state.oauth_client_manager.remove_client(client_key)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Set new tool server connections
|
# Set new tool server connections
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ async def process_pipeline_inlet_filter(request, payload, user, models):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
urlIdx = int(urlIdx)
|
urlIdx = int(urlIdx)
|
||||||
except:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
url = request.app.state.config.OPENAI_API_BASE_URLS[urlIdx]
|
url = request.app.state.config.OPENAI_API_BASE_URLS[urlIdx]
|
||||||
@@ -123,7 +123,7 @@ async def process_pipeline_outlet_filter(request, payload, user, models):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
urlIdx = int(urlIdx)
|
urlIdx = int(urlIdx)
|
||||||
except:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
url = request.app.state.config.OPENAI_API_BASE_URLS[urlIdx]
|
url = request.app.state.config.OPENAI_API_BASE_URLS[urlIdx]
|
||||||
|
|||||||
@@ -1688,7 +1688,7 @@ def process_file(
|
|||||||
VECTOR_DB_CLIENT.delete_collection(
|
VECTOR_DB_CLIENT.delete_collection(
|
||||||
collection_name=f"file-{file.id}"
|
collection_name=f"file-{file.id}"
|
||||||
)
|
)
|
||||||
except:
|
except Exception:
|
||||||
# Audio file upload pipeline
|
# Audio file upload pipeline
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -661,7 +661,7 @@ async def yjs_document_update(sid, data):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
await stop_item_tasks(REDIS, document_id)
|
await stop_item_tasks(REDIS, document_id)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
user_id = data.get("user_id", sid)
|
user_id = data.get("user_id", sid)
|
||||||
|
|||||||
@@ -1926,7 +1926,7 @@ async def chat_completion_files_handler(
|
|||||||
queries_response = {"queries": [queries_response]}
|
queries_response = {"queries": [queries_response]}
|
||||||
|
|
||||||
queries = queries_response.get("queries", [])
|
queries = queries_response.get("queries", [])
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
await __event_emitter__(
|
await __event_emitter__(
|
||||||
@@ -2196,7 +2196,7 @@ async def process_chat_payload(request, form_data, user, metadata, model):
|
|||||||
form_data = apply_system_prompt_to_body(
|
form_data = apply_system_prompt_to_body(
|
||||||
system_message.get("content"), form_data, metadata, user, replace=True
|
system_message.get("content"), form_data, metadata, user, replace=True
|
||||||
) # Required to handle system prompt variables
|
) # Required to handle system prompt variables
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
form_data = await convert_url_images_to_base64(form_data)
|
form_data = await convert_url_images_to_base64(form_data)
|
||||||
@@ -3338,7 +3338,7 @@ async def streaming_chat_response_handler(response, ctx):
|
|||||||
if match:
|
if match:
|
||||||
try:
|
try:
|
||||||
attr_content = match.group(1) if match.group(1) else ""
|
attr_content = match.group(1) if match.group(1) else ""
|
||||||
except:
|
except Exception:
|
||||||
attr_content = ""
|
attr_content = ""
|
||||||
|
|
||||||
attributes = extract_attributes(attr_content)
|
attributes = extract_attributes(attr_content)
|
||||||
|
|||||||
Reference in New Issue
Block a user