Skip to content

Comments

Fix string formatting in exception constructors across codebase#3578

Open
bysiber wants to merge 1 commit intotornadoweb:masterfrom
bysiber:fix/exception-string-formatting
Open

Fix string formatting in exception constructors across codebase#3578
bysiber wants to merge 1 commit intotornadoweb:masterfrom
bysiber:fix/exception-string-formatting

Conversation

@bysiber
Copy link

@bysiber bysiber commented Feb 20, 2026

Several raise statements across the codebase pass format arguments to exception constructors using a comma instead of % operator:

# Before (comma creates a tuple message):
raise ValueError("message %s", value)

# After (proper string formatting):
raise ValueError("message %s" % value)

When Python's Exception.__init__ receives multiple arguments, str(e) shows the raw tuple representation instead of a formatted message. For example, ValueError("unsupported auth_mode %s", "digest") displays as:

ValueError: ('unsupported auth_mode %s', 'digest')

instead of:

ValueError: unsupported auth_mode digest

Affected locations:

  • web.py: _convert_header_value, xsrf_token, stream_request_body, _has_stream_request_body
  • websocket.py: _PerMessageDeflateCompressor.__init__, _PerMessageDeflateDecompressor.__init__, _process_server_headers
  • simple_httpclient.py: HTTP basic auth mode validation
  • netutil.py: Unix socket bind validation
  • concurrent.py: run_on_executor argument validation

Several exception raise statements across the codebase use a comma
instead of % for string formatting, e.g.:
  raise ValueError("message %s", value)
instead of:
  raise ValueError("message %s" % value)

This causes the exception to store a tuple as its message rather
than a properly formatted string, making error messages confusing
and harder to debug.
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.

1 participant