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

Validate component IDs are unique #370

Merged
merged 1 commit into from Apr 24, 2022
Merged

Validate component IDs are unique #370

merged 1 commit into from Apr 24, 2022

Conversation

ghost
Copy link

@ghost ghost commented Apr 18, 2022

The spin.toml configuration file currently loads without error when multiple components use the same id. This PR adds a uniqueness constraint in the loader crate which will fail to load a configuration file with multiple defined components sharing an identifier.

See #340 for more details.

crates/loader/src/local/mod.rs Outdated Show resolved Hide resolved
crates/loader/src/local/mod.rs Outdated Show resolved Hide resolved
@radu-matei
Copy link
Member

radu-matei commented Apr 18, 2022

While you're iterating on the PR, keep an eye out for cargo clippy suggestions:

error: avoid using `collect()` when not needed
  --> crates/loader/src/local/mod.rs:75:82
   |
75 |     let component_ids: Vec<String> = raw.components.iter().map(|c| c.id.clone()).collect();
   |                                                                                  ^^^^^^^
76 |     for component in &mut raw.components {
77 |         if component_ids.contains(&component.id) {
   |            ------------------------------------- the iterator could be used here instead
   |
   = note: `-D clippy::needless-collect` implied by `-D warnings`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_collect
help: check if the original Iterator contains an element instead of collecting then checking
   |
75 ~     
76 |     for component in &mut raw.components {
77 ~         if raw.components.iter().map(|c| c.id.clone()).any(|x| x == component.id) {
   |

crates/loader/src/local/mod.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@itowlson itowlson left a comment

Choose a reason for hiding this comment

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

Nice one - thanks for tackling this. I had just a couple of suggestions but otherwise looks good!

crates/loader/src/local/mod.rs Outdated Show resolved Hide resolved
crates/loader/src/local/mod.rs Outdated Show resolved Hide resolved
@ghost ghost marked this pull request as ready for review April 24, 2022 15:44
@ghost
Copy link
Author

ghost commented Apr 24, 2022

Applied the feedback and am happier with how the code looks now. Thanks again for feedback! I'll squash my commits after a review unless there are more changes requested.

Copy link
Member

@radu-matei radu-matei left a comment

Choose a reason for hiding this comment

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

Thank you so much for your contribution, @0xcodeboi!

LGTM

@radu-matei radu-matei merged commit ada4521 into fermyon:main Apr 24, 2022
@ghost ghost deleted the 340-validate-component-unique-ids branch April 24, 2022 22:40
@ghost ghost mentioned this pull request Apr 25, 2022
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.

3 participants