Skip to content

Commit 8922430

Browse files
Ensure before_sleep_log message isn't multiline
Some exceptions add extra `\n` characters to their message, causing the last . in the log to be a new line.
1 parent 0d40e76 commit 8922430

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fixes:
2+
- |
3+
Strip the ``str`` representation of the exception to avoid multiline
4+
log output from ``before_sleep()`` when some exceptions include ``\n``
5+
characters at the end of their string representation.

tenacity/before_sleep.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ def log_it(retry_state: "RetryCallState") -> None:
4646

4747
if retry_state.outcome.failed:
4848
ex = retry_state.outcome.exception()
49-
verb, value = "raised", f"{ex.__class__.__name__}: {ex}"
49+
exception_str = str(ex).strip() # Ensure message isn't multiline.
50+
verb, value = "raised", f"{ex.__class__.__name__}: {exception_str}"
5051

5152
if exc_info:
5253
local_exc_info = retry_state.outcome.exception()

0 commit comments

Comments
 (0)