use super::*;
use std::convert::Infallible;
use thiserror::Error;
use tokio::sync::mpsc::error::SendError;
use tokio::sync::oneshot::error::RecvError;
#[derive(Error, Debug)]
pub enum SocketError {
#[error("io error: {0}")]
Io(#[from] std::io::Error),
#[error("start-up aborted")]
StartupAborted,
#[error("internal client channel unexpectedly closed")]
ClientChannelClosed,
#[error("timeout opening socket {0}")]
TimeoutOpeningSocket(String),
#[error("permission denied opening socket {0}")]
PermissionDeniedOpeningSocket(String),
#[error("gave up retrying command {0} while attaching to event stream")]
AttachFailed(String),
}
#[derive(Error, Debug, Clone)]
pub enum ClientError {
#[error("Supplicant reported request failed")]
Failed,
#[error("error {error} parsing response: \n{failed_response}")]
ParsingResponse {
#[source]
error: ParseError,
failed_response: String,
},
#[error("timeout waiting for response")]
Timeout,
#[error("Request was too big only sent {0} of {1} bytes")]
DidNotWriteAllBytes(usize, usize),
#[error("Runner task not running")]
RunnerNotRunning,
#[error("Select already pending")]
PendingSelect,
#[error("PSK is not a valid WPA passphrase")]
InvalidPsk,
#[error("BSSID is not a valid MAC address")]
InvalidBssid,
}
#[derive(Error, Debug, Clone)]
pub enum ParseError {
#[error("Didn't get expected literal \"OK\" response")]
NotOK,
#[error("error parsing config: {0}")]
ParseConfig(#[from] config::ConfigError),
#[error("error parsing int: {0}")]
ParseInt(#[from] std::num::ParseIntError),
#[error("utf8 error: {0}")]
Utf8Parse(#[from] std::str::Utf8Error),
}
impl From<Infallible> for ParseError {
fn from(_: Infallible) -> Self {
unreachable!()
}
}
impl<T> From<SendError<T>> for ClientError {
fn from(_: SendError<T>) -> Self {
ClientError::RunnerNotRunning
}
}
impl From<RecvError> for ClientError {
fn from(_: RecvError) -> Self {
ClientError::RunnerNotRunning
}
}