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

Improve error message when initializing from a Structured Config with incorrect type #559

Merged
merged 7 commits into from
Mar 5, 2021

Conversation

Jasha10
Copy link
Collaborator

@Jasha10 Jasha10 commented Feb 23, 2021

@Jasha10 Jasha10 force-pushed the improve-structured-conf-err-reporting2 branch from a3a2a0e to 11dd051 Compare February 23, 2021 01:39
@Jasha10 Jasha10 marked this pull request as draft February 23, 2021 01:43
tests/test_errors.py Outdated Show resolved Hide resolved
@Jasha10 Jasha10 self-assigned this Feb 24, 2021
@omry
Copy link
Owner

omry commented Feb 25, 2021

Can you add a test when the error is in a deeper level to see the resulting error message is reasonable?

maybe something like:

            create=lambda: OmegaConf.structured(
                ConcretePlugin(params=ConcretePlugin.FoobarParams(foo="x")) # type: ignore
            ),

@Jasha10 Jasha10 force-pushed the improve-structured-conf-err-reporting2 branch from 3f40dbb to 2610a53 Compare February 26, 2021 13:07
@Jasha10 Jasha10 requested a review from omry February 26, 2021 13:32
parent=dummy_parent,
)
except ValidationError as ex:
dummy_parent._format_and_raise(key=name, value=value, cause=ex)
Copy link
Owner

Choose a reason for hiding this comment

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

can you try to use format_and_raise() directly instead of through the dummy parent?
it can probably make things a bit cleaner when testing this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In f2a1bfd I've switched from dummy_parent._format_and_raise(...) to format_and_raise(node=None, ...).

The disadvantage of this change is that we no longer have object_type information in the error message (as dummy_parent was providing the object_type).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Besides the object_type issue, the error messages are also not reporting full_key accurately. I think that reporting on full_key would be easiest if we pass a parent_node into the get_structured_config_data function (so that full_key could be computed using the parent config). This change would require some plumbing of the methods that call get_structured_config_data. I can give it a try if you're interested...

Copy link
Owner

Choose a reason for hiding this comment

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

I think this will trivially easier once we have the structured_ir diff baked and ready.
for now this is good enough.

tests/test_errors.py Outdated Show resolved Hide resolved
Repository owner deleted a comment from Jasha10 Mar 3, 2021
@Jasha10 Jasha10 requested a review from omry March 3, 2021 09:16
Copy link
Owner

@omry omry left a comment

Choose a reason for hiding this comment

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

looking better.
make a pass to cleanup left overs from previous attempt.

omegaconf/_utils.py Outdated Show resolved Hide resolved
Copy link
Owner

@omry omry left a comment

Choose a reason for hiding this comment

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

awesome :)

@omry omry marked this pull request as ready for review March 5, 2021 01:43
@omry omry changed the title hacky attempt to fix #435 Improve error message when initializing from a Structured Config with incorrect type Mar 5, 2021
@omry
Copy link
Owner

omry commented Mar 5, 2021

Can you add a news fragment file? feel free to squash and merge in once you do.

@Jasha10 Jasha10 merged commit 7dbb11a into omry:master Mar 5, 2021
@Jasha10 Jasha10 deleted the improve-structured-conf-err-reporting2 branch March 5, 2021 04:49
odelalleau pushed a commit to odelalleau/omegaconf that referenced this pull request Mar 10, 2021
… incorrect type (omry#559)

* test error message
* use format_and_raise() directly
* add 435.bugfix news fragment
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.

Unclear error: incorrect type for field of dataclass instance
2 participants