feat: add thiserror annotations to error

This commit is contained in:
Jindřich Moravec 2024-01-23 21:02:13 +01:00
parent 1d746430d2
commit f47fd24232
3 changed files with 13 additions and 1 deletions

1
Cargo.lock generated
View file

@ -255,6 +255,7 @@ name = "minisql"
version = "0.1.0"
dependencies = [
"bimap",
"thiserror",
]
[[package]]

View file

@ -7,3 +7,4 @@ edition = "2021"
[dependencies]
bimap = "0.6.3"
thiserror = "1.0.50"

View file

@ -1,17 +1,27 @@
use thiserror::Error;
use crate::internals::row::ColumnPosition;
use crate::schema::{ColumnName, TableName};
use crate::operation::InsertionValues;
use crate::type_system::{DbType, Uuid, Value};
#[derive(Debug)]
#[derive(Debug, Error)]
pub enum Error {
#[error("table {0} does not exist")]
TableDoesNotExist(TableName),
#[error("column {1} of table {0} does not exist")]
ColumnDoesNotExist(TableName, ColumnName),
#[error("column position {1} of table {0} does not exist")]
ColumnPositionDoesNotExist(TableName, ColumnPosition),
#[error("column {1} of table {0} has unexpected type {2:?} and value {3:?}")]
ValueDoesNotMatchExpectedType(TableName, ColumnName, DbType, Value),
#[error("table {0} already contains row with id {1}")]
AttemptingToInsertAlreadyPresentId(TableName, Uuid),
#[error("table {0} is missing annotation for column {1}")]
MissingTypeAnnotationOfColumn(TableName, ColumnPosition),
#[error("table {0} is missing column {1} in insert values {2:?}")]
MissingColumnInInsertValues(TableName, ColumnName, InsertionValues),
#[error("table {0} has mismatch between insert values {1:?} and columns")]
MismatchBetweenInsertValuesAndColumns(TableName, InsertionValues),
#[error("table {0} cannot be indexed on column {1}")]
AttemptToIndexNonIndexableColumn(TableName, ColumnName),
}