mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-05 18:20:34 +00:00
argument: convert to ThisError and sort
BUG=b:197143586 TEST=cargo check Change-Id: I8d75003c65e647f1cf4962f390823d5c15169a57 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3105434 Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
This commit is contained in:
parent
8eda3ea975
commit
31b6a00062
1 changed files with 23 additions and 31 deletions
|
@ -43,47 +43,39 @@
|
|||
//! }
|
||||
//! ```
|
||||
|
||||
use std::fmt::{self, Display};
|
||||
use std::result;
|
||||
|
||||
use remain::sorted;
|
||||
use thiserror::Error;
|
||||
|
||||
/// An error with argument parsing.
|
||||
#[derive(Debug)]
|
||||
#[sorted]
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Error {
|
||||
/// There was a syntax error with the argument.
|
||||
Syntax(String),
|
||||
/// The argument's name is unused.
|
||||
UnknownArgument(String),
|
||||
/// The argument was required.
|
||||
#[error("expected argument: {0}")]
|
||||
ExpectedArgument(String),
|
||||
/// The argument's given value is invalid.
|
||||
InvalidValue { value: String, expected: String },
|
||||
/// The argument was already given and none more are expected.
|
||||
TooManyArguments(String),
|
||||
/// The argument expects a value.
|
||||
#[error("expected parameter value: {0}")]
|
||||
ExpectedValue(String),
|
||||
/// The argument does not expect a value.
|
||||
UnexpectedValue(String),
|
||||
/// The argument's given value is invalid.
|
||||
#[error("invalid value {value:?}: {expected}")]
|
||||
InvalidValue { value: String, expected: String },
|
||||
/// The help information was requested
|
||||
#[error("help was requested")]
|
||||
PrintHelp,
|
||||
}
|
||||
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
use self::Error::*;
|
||||
|
||||
match self {
|
||||
Syntax(s) => write!(f, "syntax error: {}", s),
|
||||
UnknownArgument(s) => write!(f, "unknown argument: {}", s),
|
||||
ExpectedArgument(s) => write!(f, "expected argument: {}", s),
|
||||
InvalidValue { value, expected } => {
|
||||
write!(f, "invalid value {:?}: {}", value, expected)
|
||||
}
|
||||
TooManyArguments(s) => write!(f, "too many arguments: {}", s),
|
||||
ExpectedValue(s) => write!(f, "expected parameter value: {}", s),
|
||||
UnexpectedValue(s) => write!(f, "unexpected parameter value: {}", s),
|
||||
PrintHelp => write!(f, "help was requested"),
|
||||
}
|
||||
}
|
||||
/// There was a syntax error with the argument.
|
||||
#[error("syntax error: {0}")]
|
||||
Syntax(String),
|
||||
/// The argument was already given and none more are expected.
|
||||
#[error("too many arguments: {0}")]
|
||||
TooManyArguments(String),
|
||||
/// The argument does not expect a value.
|
||||
#[error("unexpected parameter value: {0}")]
|
||||
UnexpectedValue(String),
|
||||
/// The argument's name is unused.
|
||||
#[error("unknown argument: {0}")]
|
||||
UnknownArgument(String),
|
||||
}
|
||||
|
||||
/// Result of a argument parsing.
|
||||
|
|
Loading…
Reference in a new issue