Skip to content

Commit 33dee72

Browse files
ericphansonpytorchmergebot
authored andcommitted
Reraise worker errors as runtime errors in more cases when the original exception can't be constructed (pytorch#140911)
related to pytorch#34130 when pytorch attempts to re-raise an exception from a worker process (e.g. multiprocessing dataloader), if it can't reconstruct the original exception message due to a type error, it instead raises it as a runtime error. However, if it can't reconstruct the exception for some other reason, it throws an error with a stacktrace pointing to the `ExceptionWrapper` code rather than the original underlying issue. One case in which I run into this is with boto3's [HTTPClientError](https://github.com/boto/botocore/blob/66dc1f8d52aab1da8c2e03c722d15567b682a874/botocore/exceptions.py#L94)s. They must be constructed with a keyword argument `error`, but if `error` isn't passed, a `KeyError` is thrown instead of a `TypeError`, due to the particular way it is implemented: * [HTTPClientError](https://github.com/boto/botocore/blob/66dc1f8d52aab1da8c2e03c722d15567b682a874/botocore/exceptions.py#L94)'s constructor excepts variable keyword arguments it passes to `super` (BotoCoreError) * [it also defines a field `fmt` with `error`](https://github.com/boto/botocore/blob/66dc1f8d52aab1da8c2e03c722d15567b682a874/botocore/exceptions.py#L95) * BotoCoreError [expects to be able to format that string with the kwargs](https://github.com/boto/botocore/blob/66dc1f8d52aab1da8c2e03c722d15567b682a874/botocore/exceptions.py#L41) So in this case, if a HTTPClientError occurs on a worker process, you simply get a `KeyError: error` with a stacktrace pointing to [this line](https://github.com/pytorch/pytorch/blob/3e2f276a1445c6e27ebeb1fa5d60bce2200af315/torch/_utils.py#L710) which is unhelpful. Instead, I propose to reraise the error as a `RuntimeError` unconditionally. Pull Request resolved: pytorch#140911 Approved by: https://github.com/vmoens
1 parent cdc03f9 commit 33dee72

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

torch/_utils.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -726,9 +726,9 @@ def reraise(self):
726726
raise self.exc_type(message=msg)
727727
try:
728728
exception = self.exc_type(msg)
729-
except TypeError:
730-
# If the exception takes multiple arguments, don't try to
731-
# instantiate since we don't know how to
729+
except Exception:
730+
# If the exception takes multiple arguments or otherwise can't
731+
# be constructed, don't try to instantiate since we don't know how to
732732
raise RuntimeError(msg) from None
733733
raise exception
734734

0 commit comments

Comments
 (0)