Skip to content

4401 improve parser error message#4402

Merged
wyli merged 3 commits intoProject-MONAI:devfrom
wyli:improve-error-msg
May 31, 2022
Merged

4401 improve parser error message#4402
wyli merged 3 commits intoProject-MONAI:devfrom
wyli:improve-error-msg

Conversation

@wyli
Copy link
Copy Markdown
Contributor

@wyli wyli commented May 30, 2022

Signed-off-by: Wenqi Li [email protected]

Fixes #4401

Description

new message shows some more details of the component:

----
Cannot instantiate 'monai.transforms.compose.Compose' with kwargs: {'transforms_wrong_key': []}
__init__() got an unexpected keyword argument 'transforms_wrong_key'
----

Traceback (most recent call last):
  File "/Users/Documents/MONAI/monai/bundle/config_item.py", line 285, in instantiate
    return instantiate(modname, **args)
  File "/Users/Documents/MONAI/monai/utils/module.py", line 224, in instantiate
    raise e
  File "/Users/Documents/MONAI/monai/utils/module.py", line 218, in instantiate
    return component(**kwargs)
TypeError: __init__() got an unexpected keyword argument 'transforms_wrong_key'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/Documents/MONAI/tests/test_config_parser.py", line 228, in test_error_instance
    parser.get_parsed_content("transform", instantiate=True, eval_expr=True)
  File "/Users/Documents/MONAI/monai/bundle/config_parser.py", line 237, in get_parsed_content
    return self.ref_resolver.get_resolved_content(id=id, **kwargs)
  File "/Users/Documents/MONAI/monai/bundle/reference_resolver.py", line 182, in get_resolved_content
    return self._resolve_one_item(id=id, **kwargs)
  File "/Users/Documents/MONAI/monai/bundle/reference_resolver.py", line 162, in _resolve_one_item
    self.resolved_content[id] = item.instantiate() if kwargs.get("instantiate", True) else item
  File "/Users/Documents/MONAI/monai/bundle/config_item.py", line 287, in instantiate
    raise RuntimeError(f"Failed to instantiate {self}.") from e
RuntimeError: Failed to instantiate {'_target_': 'Compose', 'transforms_wrong_key': []}.

Status

Ready

Types of changes

  • 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.
  • 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.

Copy link
Copy Markdown
Contributor

@Nic-Ma Nic-Ma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the enhancement, looks good to me.
Put some minor comments inline.

Thanks.

@wyli wyli force-pushed the improve-error-msg branch from 069415e to ee097c0 Compare May 31, 2022 17:29
@wyli
Copy link
Copy Markdown
Contributor Author

wyli commented May 31, 2022

/build

@wyli wyli force-pushed the improve-error-msg branch from ee097c0 to cd33ad6 Compare May 31, 2022 17:40
@wyli
Copy link
Copy Markdown
Contributor Author

wyli commented May 31, 2022

/build

@wyli wyli enabled auto-merge (squash) May 31, 2022 17:42
@wyli wyli merged commit f540e34 into Project-MONAI:dev May 31, 2022
@wyli wyli deleted the improve-error-msg branch May 31, 2022 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

improve error message of get_parsed_content

3 participants