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

Attach key to type error generated from Config::get_<type>() #413

Merged
merged 1 commit into from
Feb 2, 2023

Conversation

yuja
Copy link
Contributor

@yuja yuja commented Jan 17, 2023

This commit extracts low-level get_value() to preserve the origin as much as possible. get::() would run Value-to-Value deserialization, and the origin field would be lost there.

For scalar types, we could instead leverage get::() as the deserializer implemented for Value type invokes Value::into_() function:

fn get_string(&self, key: &str) -> Result<String> { self.get(key) }

yuja added a commit to martinvonz/jj that referenced this pull request Jan 24, 2023
I considered adding .optional() helper to lift Result to Result<Option<_>>,
but it's much simpler to expect all config sections (and maybe all keys?)
are defined by default.

The error message is a bit cryptic, but it should be improved by the following
PR if accepted.

mehcode/config-rs#413
Copy link
Collaborator

@matthiasbeyer matthiasbeyer left a comment

Choose a reason for hiding this comment

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

Sorry for not answering sooner.

I think I like what I see. Could you please rebase your PR to latest master, because we had a toml-rs update merged and that error messages you're testing for might have changed.

This commit extracts low-level get_value() to preserve the origin as much
as possible. get::<Value>() would run Value-to-Value deserialization, and
the origin field would be lost there.

For scalar types, we could instead leverage get::<T>() as the deserializer
implemented for Value type invokes Value::into_<type>() function:

    fn get_string(&self, key: &str) -> Result<String> { self.get(key) }

Signed-off-by: Yuya Nishihara <[email protected]>
@yuja
Copy link
Contributor Author

yuja commented Feb 2, 2023

Sure, rebased. The tests passed locally.

@matthiasbeyer matthiasbeyer merged commit f22aa83 into mehcode:master Feb 2, 2023
@matthiasbeyer
Copy link
Collaborator

Thanks for contributing! 🎉

@yuja yuja deleted the push-cc7b939efbd0 branch February 2, 2023 08:44
martinvonz added a commit to martinvonz/jj that referenced this pull request Mar 31, 2023
If you set e.g.`ui.pager = 5`, we currently ignore that and fall back
to the default. It seems better to let the user know that their config
is invalid, as we generally do. This commit does that. With this
change, the error message will look like this:

```
Config error: Invalid `ui.pager`: data did not match any variant of untagged enum CommandNameAndArgs
```

Maybe the key name will be redundant once the `config` crate releases
a version including mehcode/config-rs#413
(thanks, Yuya).
martinvonz added a commit to martinvonz/jj that referenced this pull request Mar 31, 2023
If you set e.g.`ui.pager = 5`, we currently ignore that and fall back
to the default. It seems better to let the user know that their config
is invalid, as we generally do. This commit does that. With this
change, the error message will look like this:

```
Config error: Invalid `ui.pager`: data did not match any variant of untagged enum CommandNameAndArgs
```

Maybe the key name will be redundant once the `config` crate releases
a version including mehcode/config-rs#413
(thanks, Yuya).
martinvonz added a commit to martinvonz/jj that referenced this pull request Mar 31, 2023
If you set e.g.`ui.pager = 5`, we currently ignore that and fall back
to the default. It seems better to let the user know that their config
is invalid, as we generally do. This commit does that. With this
change, the error message will look like this:

```
Config error: Invalid `ui.pager`: data did not match any variant of untagged enum CommandNameAndArgs
```

Maybe the key name will be redundant once the `config` crate releases
a version including mehcode/config-rs#413
(thanks, Yuya).
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.

None yet

2 participants