-
Notifications
You must be signed in to change notification settings - Fork 53
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
Fix panic in tedge_config macro when -
present in field name
#2220
Conversation
`#[tedge_config(rename = "name-with-hyphens")]` panicked because of hyphens in the rename field. This occured because a test that was being generated to test that field did not remove hyphens from the identifier name, e.g: > error: proc macro panicked > ... > = help: message: `"example_value_can_be_deserialized_for_run_name-with-hyphens_example_0"` is not a valid identifier Was fixed by replacing hyphens with underscores in identifier name. Signed-off-by: Marcel Guzik <marcel.guzik@inetum.com>
#[tedge_config(rename = "type")] | ||
ty: String, | ||
|
||
#[tedge_config(rename = "hyphen-separated-field", example = "hsf")] |
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.
One thing I noticed is that the panic was not triggered with #[tedge_config(rename = "hyphen-separated-field")]
and I also had to add example = hsf
in the macro. Is this intended behaviour?
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.
Yes, the generated tests exist to verify the examples are valid, so there is no test if no example is provided, and if there was a second example two tests would be generated.
Codecov Report
Additional details and impacted files
|
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.
This looks good to me. Out of interest, what are you intending to use hyphens for? I'm just wondering as we use underscores elsewhere in tedge.toml, and using a different casing style may be confusing.
Robot Results
|
Yes I would not advise to use hypens as this makes translating the configuration name to the environment variable equivalent more complicated as environment variables should only match the following regex (for compatibility): |
I was just testing how the config options would look like with hyphens, and stumbled on this bug. I don't intend to use them for any configuration options. |
Obviously this bug was never the right behaviour, but I'm wondering whether characters that can't be (widely) used in environment variable names should be explicitly rejected with an appropriate compiler error explaining why we don't support them, in case someone accidentally uses incorrect casing in the future. |
Proposed changes
#[tedge_config(rename = "name-with-hyphens")]
panicked because of hyphens in the rename field. This occured because a test that was being generated to test that field did not remove hyphens from the identifier name, e.g:Was fixed by replacing hyphens with underscores in identifier name.
Types of changes
Paste Link to the issue
Checklist
cargo fmt
as mentioned in CODING_GUIDELINEScargo clippy
as mentioned in CODING_GUIDELINESFurther comments