tenacity icon indicating copy to clipboard operation
tenacity copied to clipboard

Ensure `before_sleep_log` message isn't multiline

Open sebastian-correa opened this issue 11 months ago • 4 comments

Some exceptions add extra \n characters to their message, causing the last . in the log to be a new line.

sebastian-correa avatar Jan 31 '25 22:01 sebastian-correa

⚠️ No release notes detected. Please make sure to use reno to add a changelog entry.

mergify[bot] avatar Jan 31 '25 22:01 mergify[bot]

I'm failing to see how this is a problem in tenacity itself and not in the so called exception though

jd avatar Feb 03 '25 08:02 jd

@jd the PR's title might be a bit overreaching, since it won't solve actual multiline string representations (i.e., if the exception has \n "in between"). However, since the tenacity log adds a. `` at the end, I think the expectation (when implemented) was that it would come immediately after the exception string, which might not be the case if it ends with \n.

I do agree that the actual problem is more probably in the exception, but tenacity logs end up split across multiple lines. I thought about implementing my own before_sleep_log, but since it uses a private function, I desisted.

sebastian-correa avatar Feb 03 '25 15:02 sebastian-correa

Right; I'd rather change the log line to not have a final . but using something like {verb}: {e}

jd avatar Feb 06 '25 08:02 jd