Skip to content

Commit

Permalink
Add ErrorKind::Internal for erroring
Browse files Browse the repository at this point in the history
  • Loading branch information
ldm0 committed May 28, 2022
1 parent 4ab1491 commit f20e5f1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions clap_derive/src/derives/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,8 @@ fn gen_parsers(
.map(|v| v.map::<::std::result::Result<#convert_type, clap::Error>, _>(#parse).collect::<::std::result::Result<Vec<_>, clap::Error>>())
.transpose()?
.unwrap_or_else(Vec::new)
).unwrap()
)
.map_err(|arr| clap::Error::raw(clap::ErrorKind::Internal, format!("Get value array with wrong length: {}", arr.len())))?
)
} else {
None
Expand All @@ -686,7 +687,8 @@ fn gen_parsers(
.map(|v| v.map::<::std::result::Result<#convert_type, clap::Error>, _>(#parse).collect::<::std::result::Result<Vec<_>, clap::Error>>())
.transpose()?
.unwrap_or_else(Vec::new)
).unwrap()
)
.map_err(|arr| clap::Error::raw(clap::ErrorKind::Internal, format!("Get value array with wrong length: {}", arr.len())))?
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/error/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,11 @@ pub enum ErrorKind {
/// [`Display`]: std::fmt::Display
/// [Format error]: std::fmt::Error
Format,

/// Represents Clap's internal error.
///
/// Please file a bug report at https://github.com/clap-rs/clap/issues.
Internal,
}

impl ErrorKind {
Expand Down Expand Up @@ -429,6 +434,7 @@ impl ErrorKind {
Self::ArgumentNotFound => Some("An argument wasn't found"),
Self::Io => None,
Self::Format => None,
Self::Internal => Some(crate::INTERNAL_ERROR_MSG),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,7 @@ impl Error {
ErrorKind::DisplayHelp
| ErrorKind::DisplayHelpOnMissingArgumentOrSubcommand
| ErrorKind::DisplayVersion
| ErrorKind::Internal
| ErrorKind::Io
| ErrorKind::Format => false,
}
Expand Down

0 comments on commit f20e5f1

Please sign in to comment.