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 validation to esp-config #2475

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

jessebraham
Copy link
Member

@jessebraham jessebraham commented Nov 7, 2024

Opening as a draft, as this will need rebasing and additional changes once #2422 and #2246 get merged.

I have not actually taken advantage of the validation in any of the packages depending on esp-config, not sure if that should be considered in-scope for this or be handled in a subsequent PR. Will take some time to do this.

skip-changelog added as the esp-config package does not have a CHANGELOG.md, and there are no user-facing changes here.

Closes #2206

@jessebraham jessebraham added the skip-changelog No changelog modification needed label Nov 7, 2024
/// Ensure that an integer value falls within the specified range.
IntegerInRange(Range<i128>),
/// A custom validation function to run against any supported value type.
Custom(Box<dyn Fn(&Value) -> Result<(), Error>>),
Copy link
Contributor

Choose a reason for hiding this comment

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

This is more of a general question than a review comment. Can we somehow cross-validate values using Custom? I can't figure out how right now, but I think it would be useful if we could - there are value combinations in esp-wifi that don't make much sense, for example.

Copy link
Member

Choose a reason for hiding this comment

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

Is this in the scope of esp-config, or should this be managed in the crate itself? The downstream crate will have the config in a const context, it can do the required checks there to ensure that if X is enabled Y also is or isn't etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

The downstream crate will have the config in a const context, it can do the required checks there to ensure that if X is enabled Y also is or isn't etc.

That would separate the declaration of the variables (along with their individual validation rules, which are in build.rs) from the cross-validation rules which would be in lib.rs. I'm not sure if that is the ideal state we want to have.

Copy link
Member

Choose a reason for hiding this comment

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

That's true, but we can actually couple the cross-validations into build.rs too (something I only just remembered), as generate_config returns a hashmap of the key/set values.

I guess what I'm saying is that cross-validaton may come to esp-config in the future, but I think its out of scope of individual config validation, i.e let's not try and abuse Custom to do it.

"Places the SPI driver in RAM for better performance",
Value::Bool(false),
None
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a purely theoretical question, but what does it mean to set a, say, range requirement for a boolean? I guess what I want to say is, wouldn't it be better to describe the validation rule as part of the value type, as Value::XY(default, validation_rule)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip-changelog No changelog modification needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

esp-config: validation of input
3 participants