Skip to content

fix: don't quote CatchResponseError messages in the distributed error report - #3597

Open
arieleven wants to merge 2 commits into
locustio:masterfrom
arieleven:fix/distributed-error-name-quotes
Open

arieleven wants to merge 2 commits into
locustio:masterfrom
arieleven:fix/distributed-error-name-quotes

Conversation

@arieleven

Copy link
Copy Markdown
Contributor

Requested by Taltal · project thread

The console error report names a response.failure("boom") differently depending on the run mode:

  • standalone: GET /x: boom
  • distributed (on the master): GET /x: 'boom'

In distributed mode the master only has the error as a string, CatchResponseError('boom'), and StatsError.to_name() slices off CatchResponseError( and ). What remains is the repr of the message, quotes and escapes included (it's "bad" comes out as 'it\'s "bad"'). #2712 removed one extra layer of quoting here; this is the layer that was left.

The fix parses the unwrapped text with ast.literal_eval and uses the result when it is a string. Anything else (several args, a non-literal repr) is printed as before.

test_error_name_same_in_standalone_and_distributed_mode checks both modes give the same name for a plain message and one with quotes. It fails on master and passes with the fix.

  • locust/test/test_stats.py: 72 passed. locust/test/test_runners.py: 112 passed, 3 skipped (test_undefined_custom_message failed once in a combined run and passed on rerun, also on master in isolation; it looks timing related).
  • ruff check ., ruff format --check and mypy locust/stats.py are clean.

I used Claude Code to help find and write this fix. I reviewed and tested the change.

… report

In distributed mode the master only sees errors as strings, so
StatsError.to_name() unwraps "CatchResponseError(...)" by slicing off the
class name. What is left is the repr() of the message, so the console
error report shows response.failure("boom") as 'boom' on a master, while a
standalone run shows boom.

Parse the unwrapped text as a Python literal and use it when it is a
string, so both modes print the same name. Anything that isn't a plain
string literal is left as before.
@cyberw

cyberw commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

Probably a good fix, but it needs a test case actually testing a distributed run.

@arieleven

Copy link
Copy Markdown
Contributor Author

Added one in a52a506: test_distributed_catch_response_error_name in test_runners.py starts a master and a worker, has the user fire a request with CatchResponseError('it's "bad"'), and checks the error name in the master's stats. Without the fix in stats.py it fails with 'GET /: 'it\'s "bad"'' (the repr quotes); with it the name matches standalone mode. test_runners.py and test_stats.py: 185 passed, 3 skipped.

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.

2 participants