-
Notifications
You must be signed in to change notification settings - Fork 54
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
Add a custom error message for invalid use of default(value = ...)
in define_tedge_config!
#2401
Add a custom error message for invalid use of default(value = ...)
in define_tedge_config!
#2401
Conversation
…in `define_tedge_config!` Signed-off-by: James Rhodes <jarhodes314@gmail.com>
Codecov Report
Additional details and impacted files
|
Robot Results
|
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.
Approved. This adds nice support for using the tedge config macro.
"Unexpected expression, `default(value = ...)` expects a literal.\n\ | ||
Perhaps you want to use `#[tedge_config(default(variable = \"Ipv4Addr::LOCALHOST\"))]`?"); |
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.
Nitpicking.
To me an expression such as Ipv4Addr::LOCALHOST
is a literal, i.e. an expression which evaluates to itself.
Maybe a lack of knowledge on Rust terminology.
That said the hint Perhaps you want to use ... variable = \"Ipv4Addr::LOCALHOST\"
is wonderful!
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.
The reference explains quite nicely what a literal is: https://doc.rust-lang.org/beta/reference/expressions/literal-expr.html#:~:text=A%20literal%20expression%20is%20an,or%20some%20other%20evaluation%20rule.
A literal expression is an expression consisting of a single token, rather than a sequence of tokens, that immediately and directly denotes the value it evaluates to, rather than referring to it by name or some other evaluation rule.
Ipv4Addr::LOCALHOST
is made of three tokens, and refers to the value by name rather than directly. Worth noting here that LOCALHOST
is an associated constant, not an enum variant, which is potentially also confusing.
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.
Indeed, I missed this single token constraint.
Proposed changes
https://github.com/thin-edge/thin-edge.io/pull/2398/files/313cc0efaac938fe47b1267d63a3d89cbb31c312..954da3d0246b6e6db4b5cd3d41421f5864ad9088#r1380338718 highlighted a usability issue with
define_tedge_config
and default values, which can either be provided usingdefault(value = true)
ordefault(variable = "Ipv4Addr::LOCALHOST")
. The distinction between these two formats is important, but subtle.This PR adds a custom error message for the case which caused confusion, pointing the user towards a suggested solution. See the screenshot below (or the added test) for the error that appears:
Types of changes
Paste Link to the issue
Checklist
cargo fmt
as mentioned in CODING_GUIDELINEScargo clippy
as mentioned in CODING_GUIDELINESFurther comments