Skip to content
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

update: Give clearer message when header encoding fails #1088

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

leondz
Copy link
Collaborator

@leondz leondz commented Jan 27, 2025

resolves #1035 (best effort)

HTTP under base RFC2616 only supports ASCII and latin-1 (iso-8859-1) encodings. This is echoed in Python's http lib implementation. When characters from outside these sets turn up in certain parts of an HTTP requests, an encoding exception is raised.

This PR catches that exception, wraps it in an error message, logs with a suggestion, and then tries to stop generation using a BadGeneratorException.

Design decisions:

  • Because the encoding is likely in the HTTP headers or other meta-information, and this information will be static across all requests, it's likely none of the requests will succeed. In this case we may as well give up the run as soon as possible, rather than skipping.
  • Because headers may contain API keys, we don't try to log or print the request that led to the failure

Verification

  • python -m pytest tests/generators/test_rest::test_rest_non_latin1

@leondz leondz added the generators Interfaces with LLMs label Jan 27, 2025
@leondz leondz changed the title update: Give clearer message when heading encoding fails update: Give clearer message when header encoding fails Jan 27, 2025
"Only latin-1 encoding supported by HTTP RFC 2616, check headers and values for unusual chars",
exc_info=uee,
)
raise BadGeneratorException from uee
Copy link
Collaborator

Choose a reason for hiding this comment

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

Having read the reported issue I think the raise here may not be an appropriate type. BadGeneratorException extends PluginConfigurationError and this error is not related to the configuration at this time.

This error seems like a new exception class may be appropriate, something like BadResponseException / InvalidResponseError / MalformedResponseException. The message helps the user understand that the issue is with the response data, however I am looking for something programatic to make it clear that the target systems response is not supported vs suggesting that configuration of the generator could be changed to avoid the issue.

@leondz
Copy link
Collaborator Author

leondz commented Jan 30, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generators Interfaces with LLMs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

error: 'latin-1' codec can't encode character '\u2026'
2 participants