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

@ -7,7 +7,7 @@ use crate::errors::*;
use crate::state::AppState;
pub async fn launch(use_base: bool) -> Result<(), LaunchError> {
pub async fn launch(use_base: bool) -> Result<(), ExecError> {
let state = APP.get().unwrap().state::<AppState>();
// do all this in a block so we don't hold the lock any longer than necessary
let mut cmd = {
@ -35,14 +35,9 @@ pub async fn launch(use_base: bool) -> Result<(), LaunchError> {
match cmd.spawn() {
Ok(_) => Ok(()),
Err(e) => {
use std::io::ErrorKind::*;
if let NotFound = e.kind() {
Err(LaunchError::ExeNotFound(cmd.get_program().to_owned()))
}
else {
Err(LaunchError::from(e))
}
}
Err(e) if std::io::ErrorKind::NotFound == e.kind() => {
Err(ExecError::NotFound(cmd.get_program().to_owned()))
},
Err(e) => Err(e.into()),
}
}