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

Error if user follows a non-existent component #951

Merged
merged 1 commit into from
Dec 11, 2022

Conversation

itowlson
Copy link
Contributor

@itowlson itowlson commented Dec 8, 2022

Fixes #944.

If a non-existent component is specified in --follow, Spin now exits with this message:

$ spin up --follow godby --follow helo
Error: The following component(s) specified in --follow do not exist in the application:
  - godby
  - helo
The following components exist:
  - gogogo
  - goodbyte
  - hello
Error: exit status: 1

(I don't know where the "exit status 1" comes from - is that an artefact of the spin trigger command failing and that output being reported by spin up @lann?)

(cc @etehtsea - it won't let me add you as a reviewer)

Signed-off-by: itowlson ivan.towlson@fermyon.com

Comment on lines 74 to 77
let unknown_names: Vec<_> = names
.iter()
.filter(|name| !component_ids.contains(name.as_str()))
.collect();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let unknown_names: Vec<_> = names
.iter()
.filter(|name| !component_ids.contains(name.as_str()))
.collect();
let unknown_names: Vec<_> = names.difference(&component_ids).collect();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bah, I knew that had to exist somewhere. Thank you!

@etehtsea
Copy link
Contributor

etehtsea commented Dec 9, 2022

I've checked it locally, and it works great!
Thanks!

Comment on lines +158 to +157
.map(|item| format!(" - {item}"))
.collect::<Vec<_>>()
.join("\n")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Almost equivalent (but with extra trailing \n):

Suggested change
.map(|item| format!(" - {item}"))
.collect::<Vec<_>>()
.join("\n")
.map(|item| format!(" - {item}\n"))
.collect()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's nice, but because I return the error message rather than fully controlling the printing it means, I end up with a blank line between the error and the exit code message:

$ spin up --follow godby --follow helo
Error: The following component(s) specified in --follow do not exist in the application:
  - helo
  - godby
The following components exist:
  - gogogo
  - hello
  - goodbyte

Error: exit status: 1

...which is neither here nor there, I'm sure, but I slightly prefer the more compact form. If we can get rid of the exit status message then this would be a good change. (And thanks for mentioning it, I didn't know collecting to String did this. Though now I do I'm not sure how I feel about it!)

Signed-off-by: itowlson <ivan.towlson@fermyon.com>
@itowlson itowlson force-pushed the follow-non-existent-component branch from b130e1d to 663a63f Compare December 11, 2022 19:24
@itowlson itowlson merged commit 5f52518 into fermyon:main Dec 11, 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.

--follow doesn't validate provided values
3 participants