combine ExecError with LaunchError and use Session::try_get() instead of matching

This commit is contained in:
2023-08-03 21:57:55 -07:00
parent 890f715388
commit a51b20add7
6 changed files with 38 additions and 43 deletions

View File

@@ -217,16 +217,6 @@ pub enum RequestError {
}
// Errors encountered while running a subprocess via creddy exec
#[derive(Debug, ThisError, AsRefStr)]
pub enum ExecError {
#[error("Please specify a command")]
NoCommand,
#[error("Failed to execute command: {0}")]
ExecutionFailed(#[from] std::io::Error)
}
#[derive(Debug, ThisError, AsRefStr)]
pub enum CliError {
#[error(transparent)]
@@ -240,9 +230,11 @@ pub enum CliError {
// Errors encountered while trying to launch a child process
#[derive(Debug, ThisError, AsRefStr)]
pub enum LaunchError {
pub enum ExecError {
#[error("Please specify a command")]
NoCommand,
#[error("Executable not found: {0:?}")]
ExeNotFound(OsString),
NotFound(OsString),
#[error("Failed to execute command: {0}")]
ExecutionFailed(#[from] std::io::Error),
#[error(transparent)]
@@ -342,14 +334,14 @@ impl Serialize for UnlockError {
}
impl Serialize for LaunchError {
impl Serialize for ExecError {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("code", self.as_ref())?;
map.serialize_entry("msg", &format!("{self}"))?;
match self {
LaunchError::GetCredentials(src) => map.serialize_entry("source", &src)?,
ExecError::GetCredentials(src) => map.serialize_entry("source", &src)?,
_ => serialize_upstream_err(self, &mut map)?,
}
map.end()