Skip to content

Commit 97678fa

Browse files
surajpaibericspod
andauthored
Remove nested error propagation on ConfigComponent instantiate (#7569)
Fixes #7451 ### Description Reduces the length of error messages and error messages being propagated twice. This helps debug better when long `ConfigComponent`s are being instantiated. Refer to issue #7451 for more details ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [x] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. Signed-off-by: Suraj Pai <[email protected]> Co-authored-by: Eric Kerfoot <[email protected]>
1 parent c86e790 commit 97678fa

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

monai/bundle/config_item.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,7 @@ def instantiate(self, **kwargs: Any) -> object:
289289
mode = self.get_config().get("_mode_", CompInitMode.DEFAULT)
290290
args = self.resolve_args()
291291
args.update(kwargs)
292-
try:
293-
return instantiate(modname, mode, **args)
294-
except Exception as e:
295-
raise RuntimeError(f"Failed to instantiate {self}") from e
292+
return instantiate(modname, mode, **args)
296293

297294

298295
class ConfigExpression(ConfigItem):

monai/utils/module.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def instantiate(__path: str, __mode: str, **kwargs: Any) -> Any:
272272
return pdb.runcall(component, **kwargs)
273273
except Exception as e:
274274
raise RuntimeError(
275-
f"Failed to instantiate component '{__path}' with kwargs: {kwargs}"
275+
f"Failed to instantiate component '{__path}' with keywords: {','.join(kwargs.keys())}"
276276
f"\n set '_mode_={CompInitMode.DEBUG}' to enter the debugging mode."
277277
) from e
278278

0 commit comments

Comments
 (0)