-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix(cli):detailed error message on sse stream specifying stacktrack,error type on client side as well #4248
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
base: main
Are you sure you want to change the base?
Changes from all commits
787e933
2d296d6
046302f
5027627
4805259
63d552e
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -761,7 +761,7 @@ async def internal_lifespan(app: FastAPI): | |||||
| async def list_apps( | ||||||
| detailed: bool = Query( | ||||||
| default=False, description="Return detailed app information" | ||||||
| ) | ||||||
| ), | ||||||
| ) -> list[str] | ListAppsResponse: | ||||||
| if detailed: | ||||||
| apps_info = self.agent_loader.list_agents_detailed() | ||||||
|
|
@@ -1469,16 +1469,31 @@ async def event_generator(): | |||||
| by_alias=True, | ||||||
| ) | ||||||
| logger.debug( | ||||||
| "Generated event in agent run streaming: %s", sse_event | ||||||
| "Generated event in agent run streaming: %s", | ||||||
| sse_event, | ||||||
| extra={ | ||||||
| "session_id": req.session_id, | ||||||
| "user_id": req.user_id, | ||||||
| }, | ||||||
| ) | ||||||
| yield f"data: {sse_event}\n\n" | ||||||
| except Exception as e: | ||||||
| logger.exception("Error in event_generator: %s", e) | ||||||
| # Yield a proper Event object for the error | ||||||
| logger.debug(f"Exception in agent run streaming: {e}", exc_info=True) | ||||||
|
Contributor
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. While the intention to provide detailed error messages to the client is good, changing the server-side logging from Additionally, for Python's logging module, it's generally recommended to pass the exception object directly as an argument rather than formatting it into an f-string when
Suggested change
|
||||||
|
|
||||||
| error_details = { | ||||||
| "error_type": type(e).__name__, | ||||||
| "error_message": str(e), | ||||||
| "timestamp": time.time(), | ||||||
DineshThumma9 marked this conversation as resolved.
Show resolved
Hide resolved
DineshThumma9 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| } | ||||||
|
|
||||||
| if logger.isEnabledFor(logging.DEBUG): | ||||||
| error_details["stacktrace"] = traceback.format_exc() | ||||||
|
|
||||||
| error_event = Event( | ||||||
| author="system", | ||||||
| content=types.Content( | ||||||
| role="model", parts=[types.Part(text=f"Error: {e}")] | ||||||
| role="model", | ||||||
| parts=[types.Part(text=json.dumps(error_details))], | ||||||
| ), | ||||||
| ) | ||||||
| yield ( | ||||||
|
|
||||||
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.
Consider using
logger.debugwith theextraparameter to include additional context, such as the session ID or user ID, in the log message. This can aid in debugging and tracing issues in multi-user environments.For example: