use std::io;
use thiserror::Error;
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug, Error)]
pub enum Error {
#[error(transparent)]
UnsupportedLaunch(#[from] UnsupportedLaunch),
#[error("failed to spawn agent process")]
SpawnProcess {
#[source]
source: io::Error,
},
#[error("launcher `{launcher}` was not found")]
MissingLauncher {
launcher: String,
#[source]
source: io::Error,
},
#[error("agent process stdin was not captured")]
MissingChildStdin,
#[error("agent process stdout was not captured")]
MissingChildStdout,
#[error(transparent)]
Protocol(#[from] agent_client_protocol::Error),
#[error("connection is closed")]
Closed,
#[error("failed to wait for agent process exit")]
WaitForProcess {
#[source]
source: io::Error,
},
#[error("failed to terminate agent process")]
KillProcess {
#[source]
source: io::Error,
},
#[error("acp connection io task ended unexpectedly")]
IoTaskTerminated,
}
#[derive(Debug, Clone, PartialEq, Eq, Error)]
pub enum UnsupportedLaunch {
#[error("binary registry distributions are not supported in v0")]
BinaryDistribution,
#[error("launch command `{command}` is not supported in v0")]
UnsupportedCommand {
command: String,
},
}
#[cfg(test)]
mod tests {
use std::io;
use super::{Error, UnsupportedLaunch};
#[test]
fn unsupported_launch_messages_are_stable() {
assert_eq!(
UnsupportedLaunch::BinaryDistribution.to_string(),
"binary registry distributions are not supported in v0"
);
assert_eq!(
UnsupportedLaunch::UnsupportedCommand {
command: "brew".into()
}
.to_string(),
"launch command `brew` is not supported in v0"
);
assert_eq!(
Error::MissingLauncher {
launcher: "npx".into(),
source: io::Error::from(io::ErrorKind::NotFound),
}
.to_string(),
"launcher `npx` was not found"
);
}
}