-
Notifications
You must be signed in to change notification settings - Fork 221
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yuja
force-pushed
the
push-cc7b939efbd0
branch
from
January 19, 2023 11:08
4d39998
to
cf5e73d
Compare
yuja
added a commit
to jj-vcs/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. rust-cli/config-rs#413
matthiasbeyer
requested changes
Feb 2, 2023
There was a problem hiding this 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
force-pushed
the
push-cc7b939efbd0
branch
from
February 2, 2023 08:32
cf5e73d
to
b24ea68
Compare
Sure, rebased. The tests passed locally. |
matthiasbeyer
approved these changes
Feb 2, 2023
Thanks for contributing! 🎉 |
martinvonz
added a commit
to jj-vcs/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 rust-cli/config-rs#413 (thanks, Yuya).
martinvonz
added a commit
to jj-vcs/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 rust-cli/config-rs#413 (thanks, Yuya).
martinvonz
added a commit
to jj-vcs/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 rust-cli/config-rs#413 (thanks, Yuya).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: