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

Changing the underlying type of an enum class options results in an unintuitive error message #1086

Closed
to-mas-kral opened this issue Nov 14, 2024 · 2 comments

Comments

@to-mas-kral
Copy link

I'm using CLI11 version 2.3.2 from vcpkg.

enum class FooType : std::uint8_t {
    A,
    B,
};

int
main(int argc, char **argv) {
    CLI::App foo_app("Foo");

    auto type = FooType::A;

    const std::map<std::string, FooType> foo_map{
        {"a", FooType::A},
        {"b", FooType::B},
    };

    foo_app.add_option("-f,--foo", type, "FooType")
        ->transform(CLI::CheckedTransformer(foo_map, CLI::ignore_case))
        ->default_val(FooType::A);
}

This code results in an exception:

terminate called after throwing an instance of 'CLI::ValidationError' what():  --foo: Check 

Changing the underlying type of FooType to std::uint32_t fixes the issue.

@phlptp
Copy link
Collaborator

phlptp commented Nov 14, 2024

Hmmm that is an interesting case. I think the reason is that "a" and "b" as as single character are valid for the type of the enum. Not sure of the chain without digging deeper, I will take a look see if something can be done or the error cleared up.

@phlptp phlptp mentioned this issue Nov 16, 2024
phlptp added a commit that referenced this issue Nov 18, 2024
Fixes issue #1086.

In the default_val enums of uint8_t would read in as a string as they
could be converted to a string. This worked ok for normal values, but
when a check was added for specific strings, it caused an error when the
default_val was added. This PR fixes the issue.

The builder for coverage was updated to CMake 3.31 (by github), this
triggered an error in the coverage tool script. This led to updating
that script, which led to uncovering some missing coverage, which led to
additional tests, which led to some issues around single element tuples
support from #1081, which led to a few other issues that came up in the
to_string operation and templates.

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@phlptp
Copy link
Collaborator

phlptp commented Nov 18, 2024

Fixed

@phlptp phlptp closed this as completed Nov 18, 2024
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

No branches or pull requests

2 participants