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

Add a custom error message for invalid use of default(value = ...) in define_tedge_config! #2401

Merged

Conversation

jarhodes314
Copy link
Contributor

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 using default(value = true) or default(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:

image

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (general improvements like code refactoring that doesn't explicitly fix a bug or add any new functionality)
  • Documentation Update (if none of the other choices apply)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Paste Link to the issue


Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA (in all commits with git commit -s)
  • I ran cargo fmt as mentioned in CODING_GUIDELINES
  • I used cargo clippy as mentioned in CODING_GUIDELINES
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

…in `define_tedge_config!`

Signed-off-by: James Rhodes <jarhodes314@gmail.com>
@jarhodes314 jarhodes314 temporarily deployed to Test Pull Request November 2, 2023 18:40 — with GitHub Actions Inactive
Copy link

codecov bot commented Nov 2, 2023

Codecov Report

Merging #2401 (9e659c7) into main (4bdae95) will decrease coverage by 0.1%.
The diff coverage is 96.1%.

Additional details and impacted files
Files Coverage Δ
crates/common/tedge_config_macros/impl/src/lib.rs 95.5% <100.0%> (+0.3%) ⬆️
...common/tedge_config_macros/impl/src/input/parse.rs 51.8% <92.3%> (+12.1%) ⬆️

... and 7 files with indirect coverage changes

Copy link
Contributor

github-actions bot commented Nov 2, 2023

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
361 0 3 361 100 53m9.085999999s

Copy link
Contributor

@didier-wenzek didier-wenzek left a 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.

Comment on lines +216 to +217
"Unexpected expression, `default(value = ...)` expects a literal.\n\
Perhaps you want to use `#[tedge_config(default(variable = \"Ipv4Addr::LOCALHOST\"))]`?");
Copy link
Contributor

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!

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@didier-wenzek didier-wenzek merged commit f2c7c61 into thin-edge:main Nov 3, 2023
18 checks passed
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