use std::path::PathBuf;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error(
"could not find the localharness binary; set ANTIGRAVITY_HARNESS_PATH, put \
`localharness` on PATH, or install the google-antigravity wheel"
)]
HarnessNotFound,
#[error("localharness at {path} is not usable: {source}")]
HarnessNotExecutable {
path: PathBuf,
source: std::io::Error,
},
#[error("localharness exited during handshake: {stderr}")]
HandshakeFailed {
stderr: String,
},
#[error("malformed handshake reply: {0}")]
Handshake(#[from] crate::handshake::DecodeError),
#[error("could not connect to the harness WebSocket on port {port} after {attempts} attempts")]
WebSocketUnreachable {
port: u16,
attempts: u32,
},
#[error("websocket error: {0}")]
#[cfg(feature = "async-client")]
WebSocket(Box<tokio_tungstenite::tungstenite::Error>),
#[error("could not decode frame: {source}")]
Decode {
source: serde_json::Error,
raw: String,
},
#[error("the harness session has closed")]
SessionClosed,
#[error("the turn failed: {message}")]
Turn {
message: String,
},
#[error("io error: {0}")]
Io(#[from] std::io::Error),
}
pub type Result<T> = std::result::Result<T, Error>;
#[cfg(feature = "async-client")]
impl From<tokio_tungstenite::tungstenite::Error> for Error {
fn from(e: tokio_tungstenite::tungstenite::Error) -> Self {
Self::WebSocket(Box::new(e))
}
}
#[cfg(feature = "async-client")]
impl Error {
pub(crate) fn decode(source: serde_json::Error, raw: impl Into<String>) -> Self {
Self::Decode {
source,
raw: raw.into(),
}
}
}