use crate::response::{Attributes, ExaError, Response, ResponseData};
use rsa;
use serde_json;
use std::fmt::Debug;
use std::num::ParseIntError;
use thiserror::Error as ThisError;
use tungstenite;
use url;
pub type Result<T> = std::result::Result<T, Error>;
impl TryFrom<Response> for (Option<ResponseData>, Option<Attributes>) {
type Error = Error;
#[inline]
fn try_from(resp: Response) -> Result<Self> {
match resp {
Response::Ok {
response_data: data,
attributes: attr,
} => Ok((data, attr)),
Response::Error { exception: e } => Err(Error::ExasolError(e)),
}
}
}
#[derive(Debug, ThisError)]
pub enum Error {
#[error(transparent)]
DriverError(#[from] DriverError),
#[error(transparent)]
ExasolError(#[from] ExaError),
}
#[derive(Debug, ThisError)]
pub enum DriverError {
#[error(transparent)]
BindError(#[from] BindError),
#[error(transparent)]
DataError(#[from] DataError),
#[error(transparent)]
ConversionError(#[from] ConversionError),
#[error(transparent)]
RequestError(#[from] RequestError),
#[error(transparent)]
ConnectionError(#[from] ConnectionError),
}
#[derive(Debug, ThisError)]
pub enum BindError {
#[error("Missing parameter to bind for {0}")]
MappingError(String),
#[error("Parameter type must serialize to a sequence or map")]
SerializeError,
#[error(transparent)]
DeserializeError(#[from] serde_json::error::Error),
}
#[derive(Debug, ThisError)]
pub enum DataError {
#[error("Missing data for column {0}")]
MissingColumn(String),
#[error("Expecting {0} data columns in array, found {1}")]
InsufficientData(usize, usize),
#[error("Data iterator items must deserialize to sequences or maps")]
InvalidIterType,
#[error(transparent)]
TypeParseError(#[from] serde_json::error::Error),
}
#[derive(Debug, ThisError)]
pub enum ConversionError {
#[error("Not a result set")]
ResultSetError,
#[error("Not a row count")]
RowCountError,
}
#[derive(Debug, ThisError)]
pub enum RequestError {
#[error(transparent)]
MessageParseError(#[from] serde_json::error::Error),
#[error(transparent)]
WebsocketError(#[from] tungstenite::error::Error),
#[error(transparent)]
CompressionError(#[from] std::io::Error),
#[error("Cannot fetch rows chunk - missing statement handle")]
MissingHandleError,
#[error("Response does not contain {0}")]
InvalidResponse(&'static str),
}
#[derive(Debug, ThisError)]
pub enum ConnectionError {
#[error("Invalid DSN provided")]
InvalidDSN,
#[error(transparent)]
DSNParseError(#[from] url::ParseError),
#[error("Cannot resolve DSN hostnames")]
HostnameResolutionError(#[from] std::io::Error),
#[error("Cannot parse provided hostname range in DSN")]
RangeParseError(#[from] ParseIntError),
#[error(transparent)]
CryptographyError(#[from] rsa::errors::Error),
#[error(transparent)]
PKCSError(#[from] rsa::pkcs1::Error),
#[error(transparent)]
WebsocketError(#[from] tungstenite::error::Error),
}