From ad08c9ab59ad6ed0cd61b3dfb0f9a8cc41044fc0 Mon Sep 17 00:00:00 2001 From: Danil Karpenko Date: Tue, 28 May 2024 12:17:04 +0200 Subject: [PATCH] feat(spawner): narrow error type --- crates/spuz_spawner/src/err.rs | 11 ----------- crates/spuz_spawner/src/lib.rs | 2 -- crates/spuz_spawner/src/process.rs | 12 ++++++++++-- 3 files changed, 10 insertions(+), 15 deletions(-) delete mode 100644 crates/spuz_spawner/src/err.rs diff --git a/crates/spuz_spawner/src/err.rs b/crates/spuz_spawner/src/err.rs deleted file mode 100644 index 869a6bb..0000000 --- a/crates/spuz_spawner/src/err.rs +++ /dev/null @@ -1,11 +0,0 @@ -use std::io::Error as IoError; - -use thiserror::Error; - -pub type Result = std::result::Result; - -#[derive(Debug, Error)] -pub enum Error { - #[error(transparent)] - Io(#[from] IoError), -} diff --git a/crates/spuz_spawner/src/lib.rs b/crates/spuz_spawner/src/lib.rs index 4325e57..515f4c9 100644 --- a/crates/spuz_spawner/src/lib.rs +++ b/crates/spuz_spawner/src/lib.rs @@ -4,13 +4,11 @@ use tokio::process::Command; use tracing::debug; pub use crate::{ - err::{Error, Result}, layer::{LaunchMod, Layer}, process::LaunchCommand, }; pub mod compose; -mod err; mod layer; mod process; #[cfg(feature = "useful-layers")] diff --git a/crates/spuz_spawner/src/process.rs b/crates/spuz_spawner/src/process.rs index 24a8f6f..58d2f91 100644 --- a/crates/spuz_spawner/src/process.rs +++ b/crates/spuz_spawner/src/process.rs @@ -1,8 +1,8 @@ use async_channel::Receiver; +use thiserror::Error; use tokio::process::Command; #[cfg(feature = "process-handle")] use { - crate::Result, async_channel::unbounded, std::sync::Arc, tokio::{io::AsyncReadExt, sync::Notify}, @@ -23,7 +23,7 @@ impl LaunchCommand { } #[cfg(feature = "process-handle")] - pub fn spawn(self) -> Result { + pub fn spawn(self) -> Result { let mut cmd = self.into_command(); let mut child = cmd.spawn()?; // # SAFETY @@ -95,3 +95,11 @@ pub struct ProcessHandle { pub exit: Arc, pub logs: Receiver, } + +#[derive(Debug, Error)] +#[error("Failed to spawn process: {source}")] +pub struct SpawnError { + #[from] + #[source] + source: std::io::Error, +}