use polars::prelude::PolarsError;
use std::{io, path::PathBuf};
use thiserror::Error;
use tokio::task::JoinError;
pub type PolarsViewResult<T> = Result<T, PolarsViewError>;
#[derive(Error, Debug)]
pub enum PolarsViewError {
#[error("Channel receive error: {0}")]
ChannelReceive(String),
#[error("CSV parsing error: {0}")]
CsvParsing(String),
#[error("File not found: {0:#?}")]
FileNotFound(PathBuf),
#[error("File type error: {0}")]
FileType(String),
#[error("IO error: {0}")]
Io(#[from] io::Error),
#[error("Initialization error: {0}")]
Initialization(String),
#[error("Invalid value for command-line argument '{arg_name}': {reason}")]
InvalidArgument {
arg_name: String, reason: String, },
#[error(
"Regex pattern '{pattern}' matched non-string columns which cannot be normalized:\n\
{columns:#?}\n\
Please adjust the regex pattern to exclusively target String columns."
)]
InvalidDataTypeForRegex {
pattern: String,
columns: Vec<String>,
},
#[error("Invalid CSV delimiter: '{0}'")] InvalidDelimiter(String),
#[error(
"Invalid regex pattern for column selection: '{0}'.\n\
Pattern must be '*' or (start with '^' and end with '$')."
)]
InvalidRegexPattern(String),
#[error("Invalid regex syntax in pattern '{pattern}'\n{error}")]
InvalidRegexSyntax { pattern: String, error: String },
#[error("Polars error: {0}")]
Polars(#[from] PolarsError),
#[error("Tokio JoinError: {0}")]
TokioJoin(#[from] JoinError),
#[error("Unsupported file type: {0}")]
UnsupportedFileType(String),
#[error("Other error: {0}")]
Other(String),
}
impl From<String> for PolarsViewError {
fn from(err: String) -> PolarsViewError {
PolarsViewError::Other(err)
}
}