Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/commands/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def reset_password(email, new_password, password_confirm):

try:
valid_password(new_password)
except:
except Exception:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While except Exception: is better than a bare except:, we can be more specific here. The valid_password function raises a ValueError on failure. Catching ValueError specifically makes the code clearer and safer.

Suggested change
except Exception:
except ValueError:

click.echo(click.style(f"Invalid password. Must match {password_pattern}", fg="red"))
return

Expand Down Expand Up @@ -74,7 +74,7 @@ def reset_email(email, new_email, email_confirm):

try:
email_validate(normalized_new_email)
except:
except Exception:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the password validation, email_validate raises a ValueError for invalid emails. It's better to catch this specific exception.

Suggested change
except Exception:
except ValueError:

click.echo(click.style(f"Invalid email: {new_email}", fg="red"))
return

Expand Down
2 changes: 1 addition & 1 deletion api/core/agent/output_parser/cot_output_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def extra_json_from_code_block(code_block) -> list[Union[list, dict]]:
json_text = re.sub(r"^[a-zA-Z]+\n", "", block.strip(), flags=re.MULTILINE)
json_blocks.append(json.loads(json_text, strict=False))
return json_blocks
except:
except Exception:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The primary exception expected in this try block is from json.loads(). It's good practice to catch the specific json.JSONDecodeError rather than a broad Exception. This makes the code's intent clearer.

Suggested change
except Exception:
except json.JSONDecodeError:

return []

code_block_cache = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, collection_name: str, config: AnalyticdbVectorOpenAPIConfig):
try:
from alibabacloud_gpdb20160503.client import Client # type: ignore
from alibabacloud_tea_openapi import models as open_api_models # type: ignore
except:
except Exception:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This try...except block is intended to handle missing optional dependencies. The specific exception raised in this case is ImportError. It's better to catch ImportError explicitly.

Suggested change
except Exception:
except ImportError:

raise ImportError(_import_err_msg)
self._collection_name = collection_name.lower()
self.config = config
Expand Down
2 changes: 1 addition & 1 deletion api/core/rag/datasource/vdb/lindorm/lindorm_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def text_exists(self, id: str) -> bool:
params["routing"] = self._routing
self._client.get(index=self._collection_name, id=id, params=params)
return True
except:
except Exception:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The text_exists method returns False if the document is not found. The self._client.get() call will raise a NotFoundError in this case. Catching this specific exception is more precise than catching a general Exception, as it avoids masking other potential issues like connection errors. You'll also need to add from opensearchpy.exceptions import NotFoundError.

Suggested change
except Exception:
except NotFoundError:

return False

def search_by_vector(self, query_vector: list[float], **kwargs: Any) -> list[Document]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def text_exists(self, id: str) -> bool:
try:
self._client.get(index=self._collection_name.lower(), id=id)
return True
except:
except Exception:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the Lindorm vector store, self._client.get() will raise NotFoundError if the document doesn't exist. Catching this specific exception is better than a broad Exception as it makes the code's behavior more predictable and avoids hiding other errors like network issues. Remember to import NotFoundError from opensearchpy.exceptions.

Suggested change
except Exception:
except NotFoundError:

return False

def search_by_vector(self, query_vector: list[float], **kwargs: Any) -> list[Document]:
Expand Down
2 changes: 1 addition & 1 deletion api/extensions/storage/aws_s3_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def exists(self, filename):
try:
self.client.head_object(Bucket=self.bucket_name, Key=filename)
return True
except:
except Exception:
return False
Comment on lines +83 to 84
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The head_object call raises a ClientError when an object is not found (404). Catching a generic Exception can mask other important errors, such as invalid credentials or network issues. It's better to specifically catch ClientError and check for the '404' error code. This makes the exists method more robust. You'll need to import ClientError from botocore.exceptions.

Suggested change
except Exception:
return False
except ClientError as e:
if e.response['Error']['Code'] == '404':
return False
else:
# Reraise other client errors
raise


def delete(self, filename: str):
Expand Down
2 changes: 1 addition & 1 deletion api/extensions/storage/oracle_oci_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def exists(self, filename):
try:
self.client.head_object(Bucket=self.bucket_name, Key=filename)
return True
except:
except Exception:
return False
Comment on lines +55 to 56
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This client behaves similarly to the AWS S3 client. The head_object call will raise a ClientError for a missing object. To make this method more robust and avoid hiding other potential errors (like configuration or permission issues), it's better to specifically catch ClientError and check for the '404' error code. Remember to import ClientError from botocore.exceptions.

Suggested change
except Exception:
return False
except ClientError as e:
if e.response['Error']['Code'] == '404':
return False
else:
# Reraise other client errors
raise


def delete(self, filename: str):
Expand Down
2 changes: 1 addition & 1 deletion api/libs/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def _unauthorized():
verified = {}
try:
verified = PassportService().verify(csrf_token)
except:
except Exception:
_unauthorized()

if verified.get("sub") != user_id:
Expand Down
2 changes: 1 addition & 1 deletion api/services/app_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def get_app_meta(self, app_model: App):
if provider is None:
raise ValueError(f"provider not found for tool {tool_name}")
meta["tool_icons"][tool_name] = json.loads(provider.icon)
except:
except Exception:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This try block can raise a ValueError (if the provider is not found) or a json.JSONDecodeError (if the icon data is invalid). It's better to catch these specific exceptions rather than a broad Exception. This makes the code's intent clearer and prevents accidentally catching unrelated errors.

Suggested change
except Exception:
except (ValueError, json.JSONDecodeError):

meta["tool_icons"][tool_name] = {"background": "#252525", "content": "\ud83d\ude01"}

return meta
Expand Down
2 changes: 1 addition & 1 deletion api/services/trigger/webhook_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ def generate_webhook_response(cls, node_config: NodeConfigDict) -> tuple[dict[st
response_data = {"message": response_body}
else:
response_data = {"status": "success", "message": "Webhook processed successfully"}
except:
except Exception:
response_data = {"message": response_body or "Webhook processed successfully"}

return response_data, status_code
Expand Down