feat: add thiserror annotations to error
This commit is contained in:
parent
1d746430d2
commit
f47fd24232
3 changed files with 13 additions and 1 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -255,6 +255,7 @@ name = "minisql"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bimap",
|
"bimap",
|
||||||
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
||||||
|
|
@ -7,3 +7,4 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bimap = "0.6.3"
|
bimap = "0.6.3"
|
||||||
|
thiserror = "1.0.50"
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,27 @@
|
||||||
|
use thiserror::Error;
|
||||||
use crate::internals::row::ColumnPosition;
|
use crate::internals::row::ColumnPosition;
|
||||||
use crate::schema::{ColumnName, TableName};
|
use crate::schema::{ColumnName, TableName};
|
||||||
use crate::operation::InsertionValues;
|
use crate::operation::InsertionValues;
|
||||||
use crate::type_system::{DbType, Uuid, Value};
|
use crate::type_system::{DbType, Uuid, Value};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Error)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
|
#[error("table {0} does not exist")]
|
||||||
TableDoesNotExist(TableName),
|
TableDoesNotExist(TableName),
|
||||||
|
#[error("column {1} of table {0} does not exist")]
|
||||||
ColumnDoesNotExist(TableName, ColumnName),
|
ColumnDoesNotExist(TableName, ColumnName),
|
||||||
|
#[error("column position {1} of table {0} does not exist")]
|
||||||
ColumnPositionDoesNotExist(TableName, ColumnPosition),
|
ColumnPositionDoesNotExist(TableName, ColumnPosition),
|
||||||
|
#[error("column {1} of table {0} has unexpected type {2:?} and value {3:?}")]
|
||||||
ValueDoesNotMatchExpectedType(TableName, ColumnName, DbType, Value),
|
ValueDoesNotMatchExpectedType(TableName, ColumnName, DbType, Value),
|
||||||
|
#[error("table {0} already contains row with id {1}")]
|
||||||
AttemptingToInsertAlreadyPresentId(TableName, Uuid),
|
AttemptingToInsertAlreadyPresentId(TableName, Uuid),
|
||||||
|
#[error("table {0} is missing annotation for column {1}")]
|
||||||
MissingTypeAnnotationOfColumn(TableName, ColumnPosition),
|
MissingTypeAnnotationOfColumn(TableName, ColumnPosition),
|
||||||
|
#[error("table {0} is missing column {1} in insert values {2:?}")]
|
||||||
MissingColumnInInsertValues(TableName, ColumnName, InsertionValues),
|
MissingColumnInInsertValues(TableName, ColumnName, InsertionValues),
|
||||||
|
#[error("table {0} has mismatch between insert values {1:?} and columns")]
|
||||||
MismatchBetweenInsertValuesAndColumns(TableName, InsertionValues),
|
MismatchBetweenInsertValuesAndColumns(TableName, InsertionValues),
|
||||||
|
#[error("table {0} cannot be indexed on column {1}")]
|
||||||
AttemptToIndexNonIndexableColumn(TableName, ColumnName),
|
AttemptToIndexNonIndexableColumn(TableName, ColumnName),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue