Skip to content

Commit

Permalink
Ensure errors are not surrounded by quotes in distributed mode (fix i…
Browse files Browse the repository at this point in the history
…s for both error summary and web)
  • Loading branch information
Lars Holmberg committed May 12, 2024
1 parent 6fb7444 commit 18048df
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions locust/stats.py
Expand Up @@ -708,7 +708,10 @@ def __init__(self, method: str, name: str, error: Exception | str | None, occurr

@classmethod
def parse_error(cls, error: Exception | str | None) -> str:
string_error = repr(error)
if isinstance(error, str):
string_error = error
else:
string_error = repr(error)
target = "object at 0x"
target_index = string_error.find(target)
if target_index < 0:
Expand All @@ -730,16 +733,19 @@ def occurred(self) -> None:

def to_name(self) -> str:
error = self.error
if isinstance(error, CatchResponseError):
# standalone
unwrapped_error = error.args[0]
if isinstance(error, str) and error.startswith("CatchResponseError("):
# distributed
length = len("CatchResponseError(")
unwrapped_error = error[length:-1]
else:
# standalone, unwrapped exception
unwrapped_error = repr(error)
if isinstance(error, str): # in distributed mode, all errors have been converted to strings
if error.startswith("CatchResponseError("):
# unwrap CatchResponseErrors
length = len("CatchResponseError(")
unwrapped_error = error[length:-1]
else:
unwrapped_error = error
else: # in standalone mode, errors are still objects
if isinstance(error, CatchResponseError):
# unwrap CatchResponseErrors
unwrapped_error = error.args[0]
else:
unwrapped_error = repr(error)

return f"{self.method} {self.name}: {unwrapped_error}"

Expand Down

0 comments on commit 18048df

Please sign in to comment.