[BE]: Enable RUFF TRY400 rule - log.exception (#153473)

Change logging.error to logging.exception to log additional information when relevant.  A few places have slipped in logging.errors in try except since I last did a clean up here and the rule is stabilized so I am enabling it codebase wide. I have NOQA'd much of our custom exception stack trace handling for RPC calls and distributed and tried to a fix a few errors based on whether we immediately reraised it or if we didn't print any exception handling where it could be useful.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/153473
Approved by: https://github.com/albanD, https://github.com/cyyever
This commit is contained in:
Aaron Gokaslan
2025-05-15 13:36:59 +00:00
committed by PyTorch MergeBot
parent 7482eb217c
commit 4f4ecc583e
23 changed files with 51 additions and 46 deletions

View File

@ -297,7 +297,7 @@ def _barrier(worker_names):
try:
_all_gather(None, set(worker_names))
except RuntimeError as ex:
logger.error("Failed to complete barrier, got error %s", ex)
logger.error("Failed to complete barrier, got error %s", ex) # noqa: TRY400
@_require_initialized
@ -312,7 +312,7 @@ def _wait_all_workers(timeout=DEFAULT_SHUTDOWN_TIMEOUT):
try:
_all_gather(None, timeout=timeout)
except RuntimeError as ex:
logger.error(
logger.error( # noqa: TRY400
"Failed to respond to 'Shutdown Proceed' in time, got error %s", ex
)
raise ex