From f47fd24232edfecd398c3aa1dd6253acb3710093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jind=C5=99ich=20Moravec?= Date: Tue, 23 Jan 2024 21:02:13 +0100 Subject: [PATCH] feat: add thiserror annotations to error --- Cargo.lock | 1 + minisql/Cargo.toml | 1 + minisql/src/error.rs | 12 +++++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 31287bb..0471c9d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -255,6 +255,7 @@ name = "minisql" version = "0.1.0" dependencies = [ "bimap", + "thiserror", ] [[package]] diff --git a/minisql/Cargo.toml b/minisql/Cargo.toml index 1a108f1..6164b6b 100644 --- a/minisql/Cargo.toml +++ b/minisql/Cargo.toml @@ -7,3 +7,4 @@ edition = "2021" [dependencies] bimap = "0.6.3" +thiserror = "1.0.50" diff --git a/minisql/src/error.rs b/minisql/src/error.rs index 6000c0e..fe11cd2 100644 --- a/minisql/src/error.rs +++ b/minisql/src/error.rs @@ -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), }