Skip to content

Conversation

ApsarasX
Copy link

@ApsarasX ApsarasX commented Oct 13, 2025

Purpose

  1. PR Refactor error handling for multiple exceptions in preprocessing #15650 forgot to modify serving_completion.py
  2. Following PR [Bugfix]: make most of test_openai_schema.py pass #17664, change str(e) to f"{e} {e.__cause__}" in the error handling for preprocessing prompt inputs.

Test Plan

Test Result


Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors error handling in several preprocessing functions. It standardizes the exception handling by consolidating multiple except blocks into one and improves the user-facing error messages by including the underlying exception cause via e.__cause__. This is a good improvement for consistency and debuggability. My review includes a suggestion to further refine the error message formatting to handle cases where e.__cause__ is None, ensuring cleaner and less confusing error outputs for the user.

except (ValueError, TypeError) as e:
logger.exception("Error in preprocessing prompt inputs")
return self.create_error_response(str(e))
return self.create_error_response(f"{e} {e.__cause__}")
Copy link
Contributor

Choose a reason for hiding this comment

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

high

While including e.__cause__ is a great improvement for error message clarity, it can be None. In that case, the current f-string would append the literal string " None" to the error message, which could be confusing for the end-user. To provide a cleaner error message, it's better to conditionally include the cause only when it exists.

Suggested change
return self.create_error_response(f"{e} {e.__cause__}")
return self.create_error_response(f"{e}{f' {e.__cause__}' if e.__cause__ else ''}")

jinja2.TemplateError) as e:
logger.exception("Error in preprocessing prompt inputs")
return self.create_error_response(str(e))
return self.create_error_response(f"{e} {e.__cause__}")
Copy link
Contributor

Choose a reason for hiding this comment

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

high

While including e.__cause__ is a great improvement for error message clarity, it can be None. In that case, the current f-string would append the literal string " None" to the error message, which could be confusing for the end-user. To provide a cleaner error message, it's better to conditionally include the cause only when it exists.

Suggested change
return self.create_error_response(f"{e} {e.__cause__}")
return self.create_error_response(f"{e}{f' {e.__cause__}' if e.__cause__ else ''}")

except (ValueError, TypeError) as e:
logger.exception("Error in preprocessing prompt inputs")
return self.create_error_response(str(e))
return self.create_error_response(f"{e} {e.__cause__}")
Copy link
Contributor

Choose a reason for hiding this comment

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

high

While including e.__cause__ is a great improvement for error message clarity, it can be None. In that case, the current f-string would append the literal string " None" to the error message, which could be confusing for the end-user. To provide a cleaner error message, it's better to conditionally include the cause only when it exists.

Suggested change
return self.create_error_response(f"{e} {e.__cause__}")
return self.create_error_response(f"{e}{f' {e.__cause__}' if e.__cause__ else ''}")

except (ValueError, TypeError, jinja2.TemplateError) as e:
logger.exception("Error in preprocessing prompt inputs")
return self.create_error_response(str(e))
return self.create_error_response(f"{e} {e.__cause__}")
Copy link
Contributor

Choose a reason for hiding this comment

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

high

While including e.__cause__ is a great improvement for error message clarity, it can be None. In that case, the current f-string would append the literal string " None" to the error message, which could be confusing for the end-user. To provide a cleaner error message, it's better to conditionally include the cause only when it exists.

Suggested change
return self.create_error_response(f"{e} {e.__cause__}")
return self.create_error_response(f"{e}{f' {e.__cause__}' if e.__cause__ else ''}")

except ValueError as e:
logger.exception("Error in preprocessing prompt inputs")
return self.create_error_response(str(e))
return self.create_error_response(f"{e} {e.__cause__}")
Copy link
Contributor

Choose a reason for hiding this comment

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

high

While including e.__cause__ is a great improvement for error message clarity, it can be None. In that case, the current f-string would append the literal string " None" to the error message, which could be confusing for the end-user. To provide a cleaner error message, it's better to conditionally include the cause only when it exists.

Suggested change
return self.create_error_response(f"{e} {e.__cause__}")
return self.create_error_response(f"{e}{f' {e.__cause__}' if e.__cause__ else ''}")

Signed-off-by: ApsarasX <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant