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

Help message on invalid component #249

Merged
merged 1 commit into from
Nov 9, 2024
Merged

Help message on invalid component #249

merged 1 commit into from
Nov 9, 2024

Conversation

Glutexo
Copy link
Owner

@Glutexo Glutexo commented Nov 9, 2024

Passing an invalid component name prints a friendly help message instead of crashing with a stack trace. This is now consistent with a situation when an invalid switch is passed.

Fixes #179.

@Glutexo Glutexo added the cli label Nov 9, 2024
@Glutexo Glutexo requested a review from nappex November 9, 2024 19:57
@Glutexo Glutexo self-assigned this Nov 9, 2024
Passing an invalid component name prints a friendly help message
instead of crashing with a stack trace. This is now consistent with a
situation when an invalid switch is passed.
@Glutexo
Copy link
Owner Author

Glutexo commented Nov 9, 2024

Shouldn’t I extend the with block to the Keyword.get call?

with {:ok, module} <-
  Map.fetch(@components, String.to_atom(component)),
  working_dir <- Keyword.get(switches, :working_dir, File.cwd!())

But Keyword.get never fails and thus doesn’t utilize the else block.

Another option would be to use Keyword.fetch instead, but it doesn’t support a default value. It would utilize the else block, but there, the default value would need to be assigned. I tried to write a code doing that and it was too complicated and didn’t make any sense. Keyword.fetch would only be useful if a missing keyword was a fatal error.

Copy link
Collaborator

@nappex nappex left a comment

Choose a reason for hiding this comment

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

Nice 👍

@nappex nappex merged commit ded9aa9 into master Nov 9, 2024
1 check passed
@Glutexo Glutexo deleted the with-module branch November 9, 2024 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show a nicer message on invalid or no module
2 participants