summaryrefslogtreecommitdiff
path: root/rustc_version/src/errors.rs
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2019-01-02 21:14:10 -0800
committerDaniel Mueller <deso@posteo.net>2019-01-02 21:14:10 -0800
commitecf3474223ca3d16a10f12dc2272e3b0ed72c1bb (patch)
tree03134a683791176b49ef5c92e8d6acd24c3b5a9b /rustc_version/src/errors.rs
parent686f61b75055ecb02baf9d9449525ae447a3bed1 (diff)
downloadnitrocli-ecf3474223ca3d16a10f12dc2272e3b0ed72c1bb.tar.gz
nitrocli-ecf3474223ca3d16a10f12dc2272e3b0ed72c1bb.tar.bz2
Update nitrokey crate to 0.2.3
This change updates the nitrokey crate to version 0.2.3. This version bumps the rand crate used to 0.6.1, which in turn requires an additional set of dependencies. Import subrepo nitrokey/:nitrokey at b3e2adc5bb1300441ca74cc7672617c042f3ea31 Import subrepo rand/:rand at 73613ff903512e9503e41cc8ba9eae76269dc598 Import subrepo rustc_version/:rustc_version at 0294f2ba2018bf7be672abd53db351ce5055fa02 Import subrepo semver-parser/:semver-parser at 750da9b11a04125231b1fb293866ca036845acee Import subrepo semver/:semver at 5eb6db94fa03f4d5c64a625a56188f496be47598
Diffstat (limited to 'rustc_version/src/errors.rs')
-rw-r--r--rustc_version/src/errors.rs79
1 files changed, 79 insertions, 0 deletions
diff --git a/rustc_version/src/errors.rs b/rustc_version/src/errors.rs
new file mode 100644
index 0000000..54557b6
--- /dev/null
+++ b/rustc_version/src/errors.rs
@@ -0,0 +1,79 @@
+use std::{self, error, fmt, io, str};
+use semver::{self, Identifier};
+
+/// The error type for this crate.
+#[derive(Debug)]
+pub enum Error {
+ /// An error ocurrend when executing the `rustc` command.
+ CouldNotExecuteCommand(io::Error),
+ /// The output of `rustc -vV` was not valid utf-8.
+ Utf8Error(str::Utf8Error),
+ /// The output of `rustc -vV` was not in the expected format.
+ UnexpectedVersionFormat,
+ /// An error ocurred in parsing a `VersionReq`.
+ ReqParseError(semver::ReqParseError),
+ /// An error ocurred in parsing the semver.
+ SemVerError(semver::SemVerError),
+ /// The pre-release tag is unknown.
+ UnknownPreReleaseTag(Identifier),
+}
+use Error::*;
+
+impl fmt::Display for Error {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ use std::error::Error;
+ match *self {
+ CouldNotExecuteCommand(ref e) => write!(f, "{}: {}", self.description(), e),
+ Utf8Error(_) => write!(f, "{}", self.description()),
+ UnexpectedVersionFormat => write!(f, "{}", self.description()),
+ ReqParseError(ref e) => write!(f, "{}: {}", self.description(), e),
+ SemVerError(ref e) => write!(f, "{}: {}", self.description(), e),
+ UnknownPreReleaseTag(ref i) => write!(f, "{}: {}", self.description(), i),
+ }
+ }
+}
+
+impl error::Error for Error {
+ fn cause(&self) -> Option<&error::Error> {
+ match *self {
+ CouldNotExecuteCommand(ref e) => Some(e),
+ Utf8Error(ref e) => Some(e),
+ UnexpectedVersionFormat => None,
+ ReqParseError(ref e) => Some(e),
+ SemVerError(ref e) => Some(e),
+ UnknownPreReleaseTag(_) => None,
+ }
+ }
+
+ fn description(&self) -> &str {
+ match *self {
+ CouldNotExecuteCommand(_) => "could not execute command",
+ Utf8Error(_) => "invalid UTF-8 output from `rustc -vV`",
+ UnexpectedVersionFormat => "unexpected `rustc -vV` format",
+ ReqParseError(_) => "error parsing version requirement",
+ SemVerError(_) => "error parsing version",
+ UnknownPreReleaseTag(_) => "unknown pre-release tag",
+ }
+ }
+}
+
+macro_rules! impl_from {
+ ($($err_ty:ty => $variant:ident),* $(,)*) => {
+ $(
+ impl From<$err_ty> for Error {
+ fn from(e: $err_ty) -> Error {
+ Error::$variant(e)
+ }
+ }
+ )*
+ }
+}
+
+impl_from! {
+ str::Utf8Error => Utf8Error,
+ semver::SemVerError => SemVerError,
+ semver::ReqParseError => ReqParseError,
+}
+
+/// The result type for this crate.
+pub type Result<T> = std::result::Result<T, Error>;