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

fix(cli): crash when using --verbosity option #1429

Merged
merged 2 commits into from
Mar 6, 2024

Conversation

ivan-aksamentov
Copy link
Member

Resolves: #1428

When using --verbosity option, Nextclade panicked with error:

The application panicked (crashed).
Message:  Mismatch between definition and access of `verbosity`. Could not downcast to log::LevelFilter, need to downcast to alloc::string::String

(in release builds the message can be different due to type mangling)

This is due to particularities of how value_parser works in clap v4, which is a replacement for possible_values functionality we used in clap v3, but which was removed in v4.

In Nextclade the verbosity filed is of type log::LevelFilter. It seems clap v4 can read a list of string values passed to value_parser and displays them correctly in the --help text, but when trying to actually pass one of these values to the --verbosity arg, clap would panic with a downcast error somewhere deep inside the library.

It's unclear to me why this is now suddenly needed, because possible_values worked just fine, but it seems that using an an iterator to the clap's PossibleValues constructed out of LevelFilter instead of strings work. I found this solution here: clap-rs/clap#4264. There are many more issues and discussions in clap repo about that. Maybe there's a better solution.

At the same time, I could not resist to clean up our verbosity.rs file, because most of the stuff we copied from clap-verbosity-flag crate and never actually use. I also use clap's default_value parameter to set a default value for the verbosity now, rather than setting a default manually on runtime.

Resolves: #1428

When using `--verbosity` option, Nextclade panicked with error:
```
The application panicked (crashed).
Message:  Mismatch between definition and access of `verbosity`. Could not downcast to log::LevelFilter, need to downcast to alloc::string::String
```
(in release builds the message can be different due to type mangling)

This is due to particularities of how `value_parser` works in `clap` v4, which is a replacement for `possible_values` functionality we used in `clap` v3, but which was removed in v4.

In Nextclade the `verbosity` filed is of type `log::LevelFilter`. It seems `clap` v4 can read a list of string values passed to `value_parser` and displays them correctly in the `--help` text, but when trying to actually pass one of these values to the `--verbosity` arg, `clap` would panic with a downcast error somewhere deep inside the library.

It's unclear to me why this is now suddenly needed, because `possible_values` worked just fine, but it seems that using an an iterator to the `clap`'s `PossibleValue`s constructed out of `LevelFilter` instead of strings work. I found this solution here: clap-rs/clap#4264. There are many more issues and discussions in clap repo about that. Maybe there's a better solution.

At the same time, I could not resist to clean up our `verbosity.rs` file, because most of the stuff we copied from `clap-verbosity-flag` crate and never actually use. I also use clap's `default_value` parameter to set a default value for the `verbosity` now, rather than setting a default manually on runtime.
Copy link

vercel bot commented Mar 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
nextclade ✅ Ready (Inspect) Visit Preview Mar 6, 2024 6:41pm

@ivan-aksamentov ivan-aksamentov merged commit f6f1dcc into master Mar 6, 2024
20 checks passed
@ivan-aksamentov ivan-aksamentov deleted the fix/cli-verbosity-crash branch March 6, 2024 19:24
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.

error when using nextclade dataset get --verbosity flag
1 participant