Skip to content

Improve invalid header encoding errors - #1194

Open
gorewilliams wants to merge 1 commit into
pydantic:mainfrom
gorewilliams:fix/header-value-encoding-error
Open

Improve invalid header encoding errors#1194
gorewilliams wants to merge 1 commit into
pydantic:mainfrom
gorewilliams:fix/header-value-encoding-error

Conversation

@gorewilliams

@gorewilliams gorewilliams commented Sep 4, 2026

Copy link
Copy Markdown

Summary

Improve the error raised when a header value cannot be encoded.

Previously, invalid header values could surface a raw UnicodeEncodeError without indicating which header caused the failure. This change raises a clearer ValueError that includes the offending header name while preserving the original encoding error as the cause.

Regression tests cover both mapping-based and iterable header construction.

Closes #864.

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

Review in cubic

@codspeed-hq

codspeed-hq Bot commented Sep 4, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 17 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing gorewilliams:fix/header-value-encoding-error (3b08e9c) with main (aaef581)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 2 files

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mention header name error message for invalid header encodings

1 participant