Commit 150ee490 authored by Ben Boeckel's avatar Ben Boeckel

errors: make error enumerations non-exhaustive

parent e44727a1
Pipeline #148000 passed with stage
......@@ -23,6 +23,7 @@ pub struct CommitId(String);
/// Errors which may occur when working with workareas.
#[derive(Debug)]
// TODO: #[non_exhaustive]
pub enum GitError {
/// Command preparation failure.
Subcommand {
......@@ -43,6 +44,11 @@ pub enum GitError {
/// The invalid ref (or description of what was wrong).
ref_: Cow<'static, str>,
},
/// This is here to force `_` matching right now.
///
/// **DO NOT USE**
#[doc(hidden)]
_NonExhaustive,
}
impl GitError {
......@@ -95,6 +101,7 @@ impl fmt::Display for GitError {
GitError::InvalidRef {
ref_,
} => write!(f, "invalid git ref: '{}'", ref_),
nonexhaustive => unreachable!("unhandled git error: {:?}", nonexhaustive),
}
}
}
......@@ -111,6 +118,7 @@ impl Error for GitError {
GitError::Git {
source, ..
} => source.as_ref().map(|err| err as &dyn Error),
nonexhaustive => unreachable!("unhandled git error: {:?}", nonexhaustive),
}
}
}
......
......@@ -27,6 +27,7 @@ use std::result::Result;
/// Steps which are involved in the submodule preparation process.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
// TODO: #[non_exhaustive]
pub enum SubmoduleIntent {
/// Creating the directory for the submodule.
CreateDirectory,
......@@ -34,10 +35,16 @@ pub enum SubmoduleIntent {
CreateGitFile,
/// Writing a `.git` file for the submodule.
WriteGitFile,
/// This is here to force `_` matching right now.
///
/// **DO NOT USE**
#[doc(hidden)]
_NonExhaustive,
}
/// Errors which may occur when using a workarea.
#[derive(Debug)]
// TODO: #[non_exhaustive]
pub enum WorkAreaError {
/// Failed to create a temporary directory for the workarea.
CreateTempDirectory {
......@@ -63,6 +70,11 @@ pub enum WorkAreaError {
/// The cause of the failure.
source: GitError,
},
/// This is here to force `_` matching right now.
///
/// **DO NOT USE**
#[doc(hidden)]
_NonExhaustive,
}
impl WorkAreaError {
......@@ -126,11 +138,13 @@ impl fmt::Display for WorkAreaError {
submodule,
)
},
_ => unreachable!("unhandled intent!"),
}
},
WorkAreaError::Git {
source,
} => write!(f, "{}", source),
nonexhaustive => unreachable!("unhandled workarea error: {:?}", nonexhaustive),
}
}
}
......@@ -150,6 +164,7 @@ impl Error for WorkAreaError {
WorkAreaError::Git {
source, ..
} => Some(source),
nonexhaustive => unreachable!("unhandled workarea error: {:?}", nonexhaustive),
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment