-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: Model addition, error log printing #2499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# coding=utf-8 | ||
|
||
import traceback | ||
from typing import Dict | ||
|
||
from django.utils.translation import gettext_lazy as _, gettext | ||
|
@@ -64,6 +64,7 @@ def is_valid(self, model_type: str, model_name, model_credential: Dict[str, obje | |
model = provider.get_model(model_type, model_name, model_credential, **model_params) | ||
model.check_auth() | ||
except Exception as e: | ||
traceback.print_exc() | ||
if isinstance(e, AppApiException): | ||
raise e | ||
if raise_exception: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The changes made in this code snippet include:
This addition provides better error handling for cases where errors occur while trying to retrieve models from the provider. It's generally good practice to catch exceptions explicitly instead of leaving them to propagate all the way up the call stack, allowing you to handle specific types of errors more gracefully and maintain application stability. Additionally, printing the traceback can help developers debug issues by providing context about what went wrong during execution. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# coding=utf-8 | ||
|
||
import traceback | ||
from typing import Dict | ||
|
||
from django.utils.translation import gettext_lazy as _, gettext | ||
|
@@ -52,6 +52,7 @@ def is_valid(self, model_type: str, model_name, model_credential: Dict[str, obje | |
for chunk in res: | ||
print(chunk) | ||
except Exception as e: | ||
traceback.print_exc() | ||
if isinstance(e, AppApiException): | ||
raise e | ||
if raise_exception: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code snippet appears to be written in Python using Django framework. Here are some points of review:
Overall, the code looks well-structured with proper error handling in place. It would benefit from additional comments and possibly adjustments to improve readability and maintainability. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your code looks mostly clean and well-organized, but there are a few potential improvements:
traceback.print_exc()
function is good for debugging purposes, especially when you're working remotely or in an environments where logging might not be set up properly. However, I would recommend adding more detail to the exception handling logic.Here's one way it could look after making these changes:
This will log both the exception message and the full stack trace, which can help in tracking down errors effectively.
"""
), make sure they are appropriately formatted across the entire class/module.Http404
,PermissionDenied
, etc., rather than bareraise
.Example:
or
These exceptions have HTTP status codes that align better with typical RESTful API usage patterns.
Overall, the code structure is clear and does what you intended it to do. With these minor adjustments, you'll have cleaner, more detailed error handling and potentially improved readability.