use std::fmt;
use std::path::PathBuf;
#[derive(Debug)]
pub enum TsGeneratorError {
EmptyQueryNameFromAnnotation(String),
EmptyQueryNameFromVarDecl,
MissingAliasForFunctions(String),
InvalidTypescriptFilePath(PathBuf),
WildcardStatementWithoutTargetTables,
WildcardStatementDeadendExpression,
WildcardStatementUnsupportedTableExpr,
UnknownPlaceholder(String),
}
impl fmt::Display for TsGeneratorError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::EmptyQueryNameFromAnnotation(query) => writeln!(
f,
"Failed to fetch query name from DB name annotation - query: {}",
query,
),
Self::EmptyQueryNameFromVarDecl => todo!(),
Self::MissingAliasForFunctions(query) => {
writeln!(f, "Missing alias when handling functions - query: {}", query,)
}
Self::InvalidTypescriptFilePath(path_buf) => {
writeln!(f, "Invalid Typescript file path - file path: {:?}", path_buf,)
}
Self::WildcardStatementWithoutTargetTables => {
writeln!(
f,
"Failed to handle a wildcard statement without target tables in `FROM` statement"
)
}
Self::WildcardStatementDeadendExpression => {
writeln!(
f,
"Failed to handle a wildcard statement as it reached a dead-end expression"
)
}
Self::WildcardStatementUnsupportedTableExpr => {
writeln!(f, "Unsupported table with joins statement detected")
}
Self::UnknownPlaceholder(placeholder) => {
writeln!(f, "The query contains unknown placeholder {}", placeholder)
}
}
}
}