Skip to content

Clarify LineTooLong error messages with context label#12393

Closed
Ricardo-M-L wants to merge 3 commits intoaio-libs:masterfrom
Ricardo-M-L:fix/line-too-long-context
Closed

Clarify LineTooLong error messages with context label#12393
Ricardo-M-L wants to merge 3 commits intoaio-libs:masterfrom
Ricardo-M-L:fix/line-too-long-context

Conversation

@Ricardo-M-L
Copy link
Copy Markdown

What do these changes do?

Closes #7177.

The LineTooLong exception previously produced a generic error message:

Got more than 8190 bytes when reading: b'GET /pathttttt...'.

…regardless of which part of the HTTP message actually overflowed the
limit. That was especially confusing for long URLs, where older versions
labelled the overflow as a "Status line is too long" (see the logs in
#7177). Even after that text was removed, the resulting message still
gave no hint about whether the URL, the status reason, a header, or a
trailer was at fault.

This PR adds an optional context parameter to
aiohttp.http_exceptions.LineTooLong and wires it through every call
site so the message now looks like:

Got more than 8190 bytes when reading request URL: b'GET /pathttttt...'.
Got more than 8190 bytes when reading header field name: b'ttt...'.
Got more than 8190 bytes when reading request/status line: b'...'.

The addition is fully backwards-compatible: the parameter defaults to
"line", so existing call-sites that have not been updated still
produce a coherent (if slightly less specific) message.

Changes

  • aiohttp/http_exceptions.py – accept and display context in LineTooLong.
  • aiohttp/_http_parser.pyx – pass "request URL" / "status reason phrase" /
    "header field name" / "header field value" from the Cython callbacks.
  • aiohttp/http_parser.py – pass "request/status line" /
    "header line with continuations" / "chunk size line" /
    "trailer line" from the pure-Python parser paths.
  • aiohttp/streams.py – label StreamReader.readuntil overflows as
    "stream until separator".

Tests

  • tests/test_http_exceptions.py::TestLineTooLong – added
    test_ctor_with_context and test_pickle_with_context, updated the
    existing message assertions for the new default label.
  • tests/test_http_parser.py::test_http_request_max_status_line_mentions_request_line
    – new regression test asserting that a too-long request line is
    described as such in the error message.

All existing match=... regex assertions anchor on the prefix
"Got more than N bytes when reading" (no trailing colon), so they
continue to pass unchanged.

Are there changes in behavior for the user?

The wording of the LineTooLong error message changes to include a
context label. Code that parses the message string could need updates;
code that catches the exception or reads err.args = (line, limit, context)
is unaffected.

Related issue number

Closes #7177.

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • Add a new news fragment into the CHANGES/ folder
    • name it <issue_id>.<type>.rst (e.g. 588.bugfix.rst)
    • if you don't have an issue_id, change it to the PR number after
      creating the PR
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation,
      for example: "Fix issue with non-ascii contents in doctest text files."

Disclosure

AI assistance (Claude) was used to draft these changes. I reviewed every
line and ran the relevant tests locally.

The `LineTooLong` exception now accepts an optional `context` parameter
describing which part of the HTTP message exceeded the size limit
(e.g. `"request URL"`, `"status reason phrase"`, `"header field name"`,
`"header field value"`, `"request/status line"`, `"trailer line"`,
`"chunk size line"`, `"header line with continuations"`, or
`"stream until separator"`). Every `LineTooLong` call site in the pure-Python
parser, the Cython parser, and `StreamReader.readuntil` now passes a
descriptive context.

Fixes the confusing "Status line is too long" error reported in aio-libs#7177
when the actual issue is a too-long URL.

Co-authored-by: Claude <[email protected]>
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Apr 19, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.92%. Comparing base (53f6e91) to head (7f169bc).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #12393   +/-   ##
=======================================
  Coverage   98.92%   98.92%           
=======================================
  Files         134      134           
  Lines       46616    46639   +23     
  Branches     2429     2430    +1     
=======================================
+ Hits        46114    46137   +23     
  Misses        373      373           
  Partials      129      129           
Flag Coverage Δ
CI-GHA 98.98% <100.00%> (+<0.01%) ⬆️
OS-Linux 98.72% <100.00%> (+<0.01%) ⬆️
OS-Windows 96.98% <100.00%> (-0.01%) ⬇️
OS-macOS 97.88% <100.00%> (-0.01%) ⬇️
Py-3.10.11 97.39% <100.00%> (-0.01%) ⬇️
Py-3.10.20 97.86% <100.00%> (-0.01%) ⬇️
Py-3.11.15 98.11% <100.00%> (+<0.01%) ⬆️
Py-3.11.9 97.64% <100.00%> (-0.01%) ⬇️
Py-3.12.10 97.73% <100.00%> (+<0.01%) ⬆️
Py-3.12.13 98.20% <100.00%> (+<0.01%) ⬆️
Py-3.13.13 98.45% <100.00%> (+<0.01%) ⬆️
Py-3.14.4 98.51% <100.00%> (+<0.01%) ⬆️
Py-3.14.4t 97.51% <100.00%> (+<0.01%) ⬆️
Py-pypy3.11.15-7.3.21 97.34% <100.00%> (-0.01%) ⬇️
VM-macos 97.88% <100.00%> (-0.01%) ⬇️
VM-ubuntu 98.72% <100.00%> (+<0.01%) ⬆️
VM-windows 96.98% <100.00%> (-0.01%) ⬇️
cython-coverage 38.18% <60.52%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 19, 2026

Merging this PR will not alter performance

✅ 67 untouched benchmarks
⏩ 4 skipped benchmarks1


Comparing Ricardo-M-L:fix/line-too-long-context (7f169bc) with master (53f6e91)

Open in CodSpeed

Footnotes

  1. 4 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.

Sphinx nitpicky mode can't resolve :exc:`~aiohttp.http_exceptions.LineTooLong`
since the exception isn't autodoc'd. Match the convention from other CHANGES
entries (e.g. 10611.bugfix.rst) and use plain inline code instead.
@Dreamsorcerer
Copy link
Copy Markdown
Member

I think the existing exception is clear enough, as it shows the actual line. The linked issue refers to "Status line is too long", which appears to have been removed in 3.13.

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

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Status line is too long" error message when URL is too long

2 participants