Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exception chaining #1945

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions detectron2/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ def from_config(cls, cfg):
def wrapped(self, *args, **kwargs):
try:
from_config_func = type(self).from_config
except AttributeError:
raise AttributeError("Class with @configurable must have a 'from_config' classmethod.")
except AttributeError as e:
raise AttributeError(
"Class with @configurable must have a 'from_config' classmethod."
) from e
if not inspect.ismethod(from_config_func):
raise TypeError("Class with @configurable must have a 'from_config' classmethod.")

Expand Down
4 changes: 2 additions & 2 deletions detectron2/data/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ def get(self, name):
"""
try:
f = self[name]
except KeyError:
except KeyError as e:
raise KeyError(
"Dataset '{}' is not registered! Available datasets are: {}".format(
name, ", ".join(list(self.keys()))
)
)
) from e
return f()

def list(self) -> List[str]:
Expand Down
4 changes: 2 additions & 2 deletions detectron2/data/transforms/augmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ def _get_aug_input_args(aug, aug_input) -> List[Any]:
for f in aug.input_args:
try:
args.append(getattr(aug_input, f))
except AttributeError:
except AttributeError as e:
raise AttributeError(
f"Augmentation {aug} needs '{f}', which is not an attribute of {aug_input}!"
)
) from e
return args


Expand Down
4 changes: 2 additions & 2 deletions detectron2/engine/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,11 @@ def _do_eval(self):
for k, v in flattened_results.items():
try:
v = float(v)
except Exception:
except Exception as e:
raise ValueError(
"[EvalHook] eval_function should return a nested dict of float. "
"Got '{}: {}' instead.".format(k, v)
)
) from e
self.trainer.storage.put_scalars(**flattened_results, smoothing_hint=False)

# Evaluation may take different time among workers.
Expand Down