use serde::{Deserialize, Serialize};
use thiserror::Error;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Error)]
#[serde(rename_all = "snake_case")]
pub enum ValidationErrorKind {
#[error("the LLM response is not valid JSON")]
InvalidJson,
#[error("required field `{field}` is missing")]
MissingField {
field: String,
},
#[error("table `{table}` is not available")]
InvalidTable {
table: String,
available_tables: Vec<String>,
},
#[error("column `{column}` is not available on table `{table}`")]
InvalidColumn {
table: String,
column: String,
available_columns: Vec<String>,
},
#[error("function `{function}` is not allowed")]
InvalidFunction {
function: String,
allowed_functions: Vec<String>,
},
#[error("type mismatch in `{expr}`: expected `{expected}`, found `{found}`")]
TypeMismatch {
expected: String,
found: String,
expr: String,
},
#[error("dialect feature `{feature}` is disabled")]
DialectFeatureDisabled {
feature: String,
},
#[error("query contains {actual} joins, but the maximum is {max}")]
TooManyJoins {
actual: usize,
max: usize,
},
#[error("aggregation mismatch: {message}")]
AggregationMismatch {
message: String,
},
#[error("query plan has {count} validation error(s)")]
MultipleErrors {
count: usize,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Error)]
#[serde(rename_all = "snake_case")]
pub enum PolicyErrorKind {
#[error("access to table `{table}` is denied")]
TableDenied {
table: String,
},
#[error("access to column `{table}.{column}` is denied")]
ColumnDenied {
table: String,
column: String,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Error)]
#[serde(rename_all = "snake_case")]
pub enum CompilationErrorKind {
#[error("dialect feature `{feature}` is not supported by the compiler")]
UnsupportedDialectFeature {
feature: String,
},
#[error("parameter placeholder `{index}` is invalid")]
InvalidPlaceholder {
index: usize,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Error)]
#[serde(rename_all = "snake_case")]
pub enum SchemaErrorKind {
#[error("table `{table}` was not found in the schema")]
TableNotFound {
table: String,
},
#[error("column `{table}.{column}` was not found in the schema")]
ColumnNotFound {
table: String,
column: String,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Error)]
#[serde(rename_all = "snake_case")]
pub enum LlmErrorKind {
#[error("LLM API returned HTTP {status}: {message}")]
ApiError {
status: u16,
message: String,
},
#[error("LLM request timed out")]
Timeout,
#[error("LLM response could not be parsed: {details}")]
ParseError {
details: String,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Error)]
#[serde(rename_all = "snake_case")]
pub enum ConfigErrorKind {
#[error("an LLM client has not been configured")]
MissingLlmClient,
#[error("a schema snapshot has not been configured")]
MissingSchema,
#[error("SQL dialect `{dialect}` is invalid")]
InvalidDialect {
dialect: String,
},
#[error("API key is required for provider `{provider}`")]
MissingApiKey {
provider: String,
},
#[error("model name must not be empty")]
EmptyModel,
#[error("failed to load configuration file `{path}`: {reason}")]
ConfigFileError {
path: String,
reason: String,
},
}