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

refactor(derive): Simplify 'error' handling #2888

Merged
merged 1 commit into from
Oct 15, 2021
Merged

Conversation

epage
Copy link
Member

@epage epage commented Oct 15, 2021

Our goal is to not panic inside of the macro (e.g. #2255). Currently,
we .unwrap() everywhere except when turning an ArgMatches into an
enum. To handle flatten, we walk through each flattened enum to
see if it can be instantiated. We don't want to mix this up with any of
the other eror cases (including further nested versions of this).

If we went straight to Result<T>, we'd have to differentiate this case
through the ErrorKind and map_err it in all other cases to prevent
it from bubbling up and confusing us.

Alternatively, we could do a more complicated type Result<Option<T>>
where the Option exists purely for this case and we can use type
checking to make sure we properly turn the Nones into errors when
needed.

Or we can bypass all of this and just ask the flattened` subcommand if
it supports the current command.

Our goal is to not panic inside of the macro (e.g. clap-rs#2255).  Currently,
we `.unwrap()` everywhere except when turning an `ArgMatches` into an
`enum`.  To handle `flatten`, we walk through each `flatten`ed enum to
see if it can be instantiated.  We don't want to mix this up with any of
the other eror cases (including further nested versions of this).

If we went straight to `Result<T>`, we'd have to differentiate this case
through the `ErrorKind` and `map_err` it in all other cases to prevent
it from bubbling up and confusing us.

Alternatively, we could do a more complicated type `Result<Option<T>>`
where the `Option` exists purely for this case and we can use type
checking to make sure we properly turn the `None`s into errors when
needed.

Or we can bypass all of this and just ask the `flatten`ed` subcommand if
it supports the current command.
Copy link
Member

@pksunkara pksunkara left a comment

Choose a reason for hiding this comment

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

bors r+

@bors
Copy link
Contributor

bors bot commented Oct 15, 2021

Build succeeded:

@bors bors bot merged commit 2795ccd into clap-rs:master Oct 15, 2021
@epage epage deleted the derive_unwrap branch October 15, 2021 23:16
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.

2 participants