From 77844ab06b58248baf57205fcb41e509c9d30e7a Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Sun, 6 Mar 2022 10:58:59 +0000 Subject: [PATCH] Convert error names according to clippy recommendations --- lib/src/ctx/reason.rs | 10 --- lib/src/dbs/executor.rs | 12 ++-- lib/src/dbs/iterator.rs | 2 +- lib/src/dbs/options.rs | 8 +-- lib/src/doc/admit.rs | 10 +-- lib/src/doc/check.rs | 2 +- lib/src/doc/empty.rs | 2 +- lib/src/doc/pluck.rs | 2 +- lib/src/err/mod.rs | 105 ++++++++++++++++++------------- lib/src/fnc/args.rs | 16 ++--- lib/src/fnc/geo.rs | 2 +- lib/src/fnc/http.rs | 12 ++-- lib/src/fnc/math.rs | 2 +- lib/src/fnc/rand.rs | 6 +- lib/src/fnc/script.rs | 2 +- lib/src/fnc/time.rs | 2 +- lib/src/kvs/file/mod.rs | 26 ++++---- lib/src/kvs/ixdb/mod.rs | 26 ++++---- lib/src/kvs/mem/mod.rs | 26 ++++---- lib/src/kvs/tikv/mod.rs | 28 ++++----- lib/src/sql/array.rs | 2 +- lib/src/sql/object.rs | 4 +- lib/src/sql/parser.rs | 20 +++--- lib/src/sql/statements/create.rs | 2 +- lib/src/sql/statements/delete.rs | 2 +- lib/src/sql/statements/insert.rs | 2 +- lib/src/sql/statements/relate.rs | 2 +- lib/src/sql/statements/update.rs | 2 +- 28 files changed, 174 insertions(+), 163 deletions(-) diff --git a/lib/src/ctx/reason.rs b/lib/src/ctx/reason.rs index 9d96db96..ccfefee4 100644 --- a/lib/src/ctx/reason.rs +++ b/lib/src/ctx/reason.rs @@ -1,4 +1,3 @@ -use crate::err::Error; use std::fmt; use std::io; @@ -17,15 +16,6 @@ impl fmt::Display for Reason { } } -impl From for Error { - fn from(reason: Reason) -> Error { - match reason { - Reason::Timedout => Error::TimeoutError, - Reason::Canceled => Error::CancelledError, - } - } -} - impl From for io::Error { fn from(reason: Reason) -> Self { let kind = match reason { diff --git a/lib/src/dbs/executor.rs b/lib/src/dbs/executor.rs index c258955a..556a9269 100644 --- a/lib/src/dbs/executor.rs +++ b/lib/src/dbs/executor.rs @@ -97,7 +97,7 @@ impl Executor { sql: v.sql, time: v.time, status: Status::Err, - detail: Some(format!("{}", Error::QueryCancelledError)), + detail: Some(format!("{}", Error::QueryCancelled)), result: None, } } @@ -109,7 +109,7 @@ impl Executor { time: v.time, status: Status::Err, detail: match v.status { - Status::Ok => Some(format!("{}", Error::QueryExecutionError)), + Status::Ok => Some(format!("{}", Error::QueryNotExecuted)), Status::Err => v.detail, }, result: None, @@ -182,7 +182,7 @@ impl Executor { Auth::Ns(v) if v == ns => opt.ns = Some(Arc::new(ns.to_owned())), _ => { opt.ns = None; - return Err(Error::NsAuthenticationError { + return Err(Error::NsNotAllowed { ns: ns.to_owned(), }); } @@ -196,7 +196,7 @@ impl Executor { Auth::Db(_, v) if v == db => opt.db = Some(Arc::new(db.to_owned())), _ => { opt.db = None; - return Err(Error::DbAuthenticationError { + return Err(Error::DbNotAllowed { db: db.to_owned(), }); } @@ -226,7 +226,7 @@ impl Executor { // Process all other normal statements _ => match self.err { // This transaction has failed - Some(_) => Err(Error::QueryExecutionError), + Some(_) => Err(Error::QueryNotExecuted), // Compute the statement normally None => { // Create a transaction @@ -244,7 +244,7 @@ impl Executor { // Catch statement timeout let res = match stm.timeout() { Some(timeout) => match ctx.is_timedout() { - true => Err(Error::QueryTimeoutError { + true => Err(Error::QueryTimeout { timer: timeout, }), false => res, diff --git a/lib/src/dbs/iterator.rs b/lib/src/dbs/iterator.rs index acc9faca..f79787cb 100644 --- a/lib/src/dbs/iterator.rs +++ b/lib/src/dbs/iterator.rs @@ -300,7 +300,7 @@ impl Iterator { fn result(&mut self, res: Result) { // Process the result match res { - Err(Error::IgnoreError) => { + Err(Error::Ignore) => { return; } Err(e) => { diff --git a/lib/src/dbs/options.rs b/lib/src/dbs/options.rs index 5ae646b4..9f7fd63e 100644 --- a/lib/src/dbs/options.rs +++ b/lib/src/dbs/options.rs @@ -79,7 +79,7 @@ impl Options { ..*self }) } else { - Err(Error::RecursiveSubqueryError { + Err(Error::TooManySubqueries { limit: self.dive, }) } @@ -167,13 +167,13 @@ impl Options { // Check whether the authentication permissions are ok pub fn check(&self, level: Level) -> Result<(), Error> { if !self.auth.check(level) { - return Err(Error::QueryPermissionsError); + return Err(Error::QueryPermissions); } if self.ns.is_none() { - return Err(Error::NsError); + return Err(Error::NsEmpty); } if self.db.is_none() { - return Err(Error::DbError); + return Err(Error::DbEmpty); } Ok(()) } diff --git a/lib/src/doc/admit.rs b/lib/src/doc/admit.rs index c80f8ef8..2959d2e5 100644 --- a/lib/src/doc/admit.rs +++ b/lib/src/doc/admit.rs @@ -16,19 +16,19 @@ impl<'a> Document<'a> { match self.id { Some(_) => Ok(()), None => match stm { - Statement::Create(_) => Err(Error::CreateStatementError { + Statement::Create(_) => Err(Error::CreateStatement { value: (*self.initial).clone(), }), - Statement::Update(_) => Err(Error::UpdateStatementError { + Statement::Update(_) => Err(Error::UpdateStatement { value: (*self.initial).clone(), }), - Statement::Relate(_) => Err(Error::RelateStatementError { + Statement::Relate(_) => Err(Error::RelateStatement { value: (*self.initial).clone(), }), - Statement::Delete(_) => Err(Error::DeleteStatementError { + Statement::Delete(_) => Err(Error::DeleteStatement { value: (*self.initial).clone(), }), - Statement::Insert(_) => Err(Error::InsertStatementError { + Statement::Insert(_) => Err(Error::InsertStatement { value: (*self.initial).clone(), }), _ => unreachable!(), diff --git a/lib/src/doc/check.rs b/lib/src/doc/check.rs index afe225a9..3f7fc1fe 100644 --- a/lib/src/doc/check.rs +++ b/lib/src/doc/check.rs @@ -24,7 +24,7 @@ impl<'a> Document<'a> { match cond { Some(v) => { match v.expr.compute(ctx, opt, txn, Some(&self.current)).await?.is_truthy() { - false => Err(Error::IgnoreError), + false => Err(Error::Ignore), true => Ok(()), } } diff --git a/lib/src/doc/empty.rs b/lib/src/doc/empty.rs index 6f4e41c1..7af2b21a 100644 --- a/lib/src/doc/empty.rs +++ b/lib/src/doc/empty.rs @@ -14,7 +14,7 @@ impl<'a> Document<'a> { _stm: &Statement, ) -> Result<(), Error> { match self.id.is_some() && self.current.is_none() { - true => Err(Error::IgnoreError), + true => Err(Error::Ignore), false => Ok(()), } } diff --git a/lib/src/doc/pluck.rs b/lib/src/doc/pluck.rs index 5156a567..126b7eec 100644 --- a/lib/src/doc/pluck.rs +++ b/lib/src/doc/pluck.rs @@ -32,7 +32,7 @@ impl<'a> Document<'a> { // Match clause match expr { Some(v) => match v { - Output::None => Err(Error::IgnoreError), + Output::None => Err(Error::Ignore), Output::Null => Ok(Value::Null), Output::Diff => Ok(self.initial.diff(&self.current, Idiom::default()).into()), Output::After => self.current.compute(ctx, opt, txn, Some(&self.current)).await, diff --git a/lib/src/err/mod.rs b/lib/src/err/mod.rs index 83abe9ae..0f6d0267 100644 --- a/lib/src/err/mod.rs +++ b/lib/src/err/mod.rs @@ -20,107 +20,131 @@ use tokio::sync::mpsc::error::SendError as TokioError; #[derive(Error, Debug)] pub enum Error { + #[error("Conditional clause is not truthy")] + Ignore, + #[error("Couldn't setup connection to underlying datastore")] - DsError, + Ds, #[error("Couldn't create a database transaction")] - TxError, + Tx, #[error("Couldn't update a finished transaction")] - TxFinishedError, + TxFinished, #[error("Couldn't write to a read only transaction")] - TxReadonlyError, + TxReadonly, #[error("Specify a namespace to use")] - NsError, + NsEmpty, #[error("Specify a database to use")] - DbError, + DbEmpty, #[error("Specify some SQL code to execute")] - EmptyError, - - #[error("The query failed to complete in time")] - TimeoutError, - - #[error("The query was cancelled before completion")] - CancelledError, + QueryEmpty, #[error("Parse error on line {line} at character {char} when parsing '{sql}'")] - ParseError { + InvalidQuery { line: usize, char: usize, sql: String, }, #[error("The JSON Patch contains invalid operations. {message}")] - PatchError { + InvalidPatch { message: String, }, #[error("Problem with embedded script function. {message}")] - LanguageError { + InvalidScript { message: String, }, #[error("Incorrect arguments for function {name}(). {message}")] - ArgumentsError { + InvalidArguments { name: String, message: String, }, #[error("Query timeout of {timer:?} exceeded")] - QueryTimeoutError { + QueryTimeout { timer: Duration, }, #[error("Query not executed due to cancelled transaction")] - QueryCancelledError, + QueryCancelled, #[error("Query not executed due to failed transaction")] - QueryExecutionError, + QueryNotExecuted, #[error("You don't have permission to perform this query type")] - QueryPermissionsError, + QueryPermissions, #[error("You don't have permission to change to the {ns} namespace")] - NsAuthenticationError { + NsNotAllowed { ns: String, }, #[error("You don't have permission to change to the {db} database")] - DbAuthenticationError { + DbNotAllowed { db: String, }, + #[error("The namespace does not exist")] + NsNotFound, + + #[error("The namespace token does not exist")] + NtNotFound, + + #[error("The namespace login does not exist")] + NlNotFound, + + #[error("The database does not exist")] + DbNotFound, + + #[error("The database token does not exist")] + DtNotFound, + + #[error("The database login does not exist")] + DlNotFound, + + #[error("The scope does not exist")] + ScNotFound, + + #[error("The scope token does not exist")] + StNotFound, + + #[error("The table does not exist")] + TbNotFound, + #[error("Too many recursive subqueries have been set")] - RecursiveSubqueryError { + TooManySubqueries { limit: usize, }, #[error("Can not execute CREATE query using value '{value}'")] - CreateStatementError { + CreateStatement { value: Value, }, #[error("Can not execute UPDATE query using value '{value}'")] - UpdateStatementError { + UpdateStatement { value: Value, }, #[error("Can not execute RELATE query using value '{value}'")] - RelateStatementError { + RelateStatement { value: Value, }, #[error("Can not execute DELETE query using value '{value}'")] - DeleteStatementError { + DeleteStatement { value: Value, }, #[error("Can not execute INSERT query using value '{value}'")] - InsertStatementError { + InsertStatement { value: Value, }, @@ -131,46 +155,43 @@ pub enum Error { }, #[error("Unable to write to the `{table}` table while setup as a view")] - TableViewError { + TableIsView { table: String, }, #[error("Database record `{thing}` already exists")] - RecordExistsError { + RecordExists { thing: Thing, }, #[error("Database index `{index}` already contains `{thing}`")] - RecordIndexError { + RecordIndex { index: String, thing: Thing, }, - #[error("Conditional clause is not truthy")] - IgnoreError, - #[error("Serde error: {0}")] - SerdeError(#[from] SerdeError), + Serde(#[from] SerdeError), #[error("Key encoding error: {0}")] - EncodeError(#[from] EncodeError), + Encode(#[from] EncodeError), #[error("Key decoding error: {0}")] - DecodeError(#[from] DecodeError), + Decode(#[from] DecodeError), #[cfg(feature = "kv-echodb")] #[error("Datastore error: {0}")] - EchoDBError(#[from] EchoDBError), + EchoDB(#[from] EchoDBError), #[cfg(feature = "kv-indxdb")] #[error("Datastore error: {0}")] - IndxDBError(#[from] IndxDBError), + IndxDB(#[from] IndxDBError), #[cfg(feature = "kv-tikv")] #[error("Datastore error: {0}")] - TiKVError(#[from] TiKVError), + TiKV(#[from] TiKVError), #[cfg(feature = "parallel")] #[error("Tokio Error: {0}")] - TokioError(#[from] TokioError<(Option, Value)>), + Tokio(#[from] TokioError<(Option, Value)>), } diff --git a/lib/src/fnc/args.rs b/lib/src/fnc/args.rs index 9ea55d76..46cd2bd0 100644 --- a/lib/src/fnc/args.rs +++ b/lib/src/fnc/args.rs @@ -24,56 +24,56 @@ pub fn check( match size { Args::None => match args.len() { 0 => func(ctx, args), - _ => Err(Error::ArgumentsError { + _ => Err(Error::InvalidArguments { name: name.to_owned(), message: String::from("The function does not expect any arguments."), }), }, Args::One => match args.len() { 1 => func(ctx, args), - _ => Err(Error::ArgumentsError { + _ => Err(Error::InvalidArguments { name: name.to_owned(), message: String::from("The function expects 1 argument."), }), }, Args::Two => match args.len() { 2 => func(ctx, args), - _ => Err(Error::ArgumentsError { + _ => Err(Error::InvalidArguments { name: name.to_owned(), message: String::from("The function expects 2 arguments."), }), }, Args::Three => match args.len() { 3 => func(ctx, args), - _ => Err(Error::ArgumentsError { + _ => Err(Error::InvalidArguments { name: name.to_owned(), message: String::from("The function expects 3 arguments."), }), }, Args::NoneOne => match args.len() { 0 | 1 => func(ctx, args), - _ => Err(Error::ArgumentsError { + _ => Err(Error::InvalidArguments { name: name.to_owned(), message: String::from("The function expects 0 or 1 arguments."), }), }, Args::NoneTwo => match args.len() { 0 | 2 => func(ctx, args), - _ => Err(Error::ArgumentsError { + _ => Err(Error::InvalidArguments { name: name.to_owned(), message: String::from("The function expects 0 or 2 arguments."), }), }, Args::NoneOneTwo => match args.len() { 0 | 1 | 2 => func(ctx, args), - _ => Err(Error::ArgumentsError { + _ => Err(Error::InvalidArguments { name: name.to_owned(), message: String::from("The function expects 0, 1, or 2 arguments."), }), }, Args::OneTwo => match args.len() { 1 | 2 => func(ctx, args), - _ => Err(Error::ArgumentsError { + _ => Err(Error::InvalidArguments { name: name.to_owned(), message: String::from("The function expects 1 or 2 arguments."), }), diff --git a/lib/src/fnc/geo.rs b/lib/src/fnc/geo.rs index c82b5816..c929f67e 100644 --- a/lib/src/fnc/geo.rs +++ b/lib/src/fnc/geo.rs @@ -92,7 +92,7 @@ pub mod hash { 2 => match args.remove(0) { Value::Geometry(Geometry::Point(v)) => match args.remove(0).as_int() { l if l > 0 && l <= 12 => Ok(geo::encode(v, l as usize).into()), - _ => Err(Error::ArgumentsError { + _ => Err(Error::InvalidArguments { name: String::from("geo::encode"), message: String::from("The second argument must be an integer greater than 0 and less than or equal to 12."), }), diff --git a/lib/src/fnc/http.rs b/lib/src/fnc/http.rs index 3f26b3ad..bb2454ff 100644 --- a/lib/src/fnc/http.rs +++ b/lib/src/fnc/http.rs @@ -5,7 +5,7 @@ use crate::sql::value::Value; pub async fn head(_ctx: &Runtime, args: Vec) -> Result { match args.len() { 1 | 2 => todo!(), - _ => Err(Error::ArgumentsError { + _ => Err(Error::InvalidArguments { name: String::from("http::head"), message: String::from("The function expects 1 or 2 arguments."), }), @@ -15,7 +15,7 @@ pub async fn head(_ctx: &Runtime, args: Vec) -> Result { pub async fn get(_ctx: &Runtime, args: Vec) -> Result { match args.len() { 1 | 2 => todo!(), - _ => Err(Error::ArgumentsError { + _ => Err(Error::InvalidArguments { name: String::from("http::get"), message: String::from("The function expects 1 or 2 arguments."), }), @@ -25,7 +25,7 @@ pub async fn get(_ctx: &Runtime, args: Vec) -> Result { pub async fn put(_ctx: &Runtime, args: Vec) -> Result { match args.len() { 1 | 2 | 3 => todo!(), - _ => Err(Error::ArgumentsError { + _ => Err(Error::InvalidArguments { name: String::from("http::put"), message: String::from("The function expects 1, 2, or 3 arguments."), }), @@ -35,7 +35,7 @@ pub async fn put(_ctx: &Runtime, args: Vec) -> Result { pub async fn post(_ctx: &Runtime, args: Vec) -> Result { match args.len() { 1 | 2 | 3 => todo!(), - _ => Err(Error::ArgumentsError { + _ => Err(Error::InvalidArguments { name: String::from("http::post"), message: String::from("The function expects 1, 2, or 3 arguments."), }), @@ -45,7 +45,7 @@ pub async fn post(_ctx: &Runtime, args: Vec) -> Result { pub async fn patch(_ctx: &Runtime, args: Vec) -> Result { match args.len() { 1 | 2 | 3 => todo!(), - _ => Err(Error::ArgumentsError { + _ => Err(Error::InvalidArguments { name: String::from("http::patch"), message: String::from("The function expects 1, 2, or 3 arguments."), }), @@ -55,7 +55,7 @@ pub async fn patch(_ctx: &Runtime, args: Vec) -> Result { pub async fn delete(_ctx: &Runtime, args: Vec) -> Result { match args.len() { 1 | 2 => todo!(), - _ => Err(Error::ArgumentsError { + _ => Err(Error::InvalidArguments { name: String::from("http::delete"), message: String::from("The function expects 1 or 2 arguments."), }), diff --git a/lib/src/fnc/math.rs b/lib/src/fnc/math.rs index 5e52cc05..d6903b6c 100644 --- a/lib/src/fnc/math.rs +++ b/lib/src/fnc/math.rs @@ -38,7 +38,7 @@ pub fn fixed(_: &Runtime, mut args: Vec) -> Result { let v = args.remove(0); match args.remove(0).as_int() { p if p > 0 => Ok(v.as_number().fixed(p as usize).into()), - _ => Err(Error::ArgumentsError { + _ => Err(Error::InvalidArguments { name: String::from("math::fixed"), message: String::from("The second argument must be an integer greater than 0."), }), diff --git a/lib/src/fnc/rand.rs b/lib/src/fnc/rand.rs index d3fa3c53..ead9518d 100644 --- a/lib/src/fnc/rand.rs +++ b/lib/src/fnc/rand.rs @@ -91,12 +91,12 @@ pub fn string(_: &Runtime, mut args: Vec) -> Result { .map(char::from) .collect::() .into()), - _ => Err(Error::ArgumentsError { + _ => Err(Error::InvalidArguments { name: String::from("rand::string"), message: String::from("To generate a string of between X and Y characters in length, the 2 arguments must be positive numbers."), }), }, - _ => Err(Error::ArgumentsError { + _ => Err(Error::InvalidArguments { name: String::from("rand::string"), message: String::from("To generate a string of between X and Y characters in length, the 2 arguments must be positive numbers."), }), @@ -108,7 +108,7 @@ pub fn string(_: &Runtime, mut args: Vec) -> Result { .map(char::from) .collect::() .into()), - _ => Err(Error::ArgumentsError { + _ => Err(Error::InvalidArguments { name: String::from("rand::string"), message: String::from("To generate a string of X characters in length, the argument must be a positive number."), }), diff --git a/lib/src/fnc/script.rs b/lib/src/fnc/script.rs index 61410d62..6acc7737 100644 --- a/lib/src/fnc/script.rs +++ b/lib/src/fnc/script.rs @@ -4,7 +4,7 @@ use crate::sql::script::Script; use crate::sql::value::Value; pub fn run(_ctx: &Runtime, _expr: Script) -> Result { - Err(Error::LanguageError { + Err(Error::InvalidScript { message: String::from("Embedded functions are not yet supported."), }) } diff --git a/lib/src/fnc/time.rs b/lib/src/fnc/time.rs index b37feb3c..9e062bf2 100644 --- a/lib/src/fnc/time.rs +++ b/lib/src/fnc/time.rs @@ -56,7 +56,7 @@ pub fn group(_: &Runtime, mut args: Vec) -> Result { .ymd(v.value.year(), v.value.month(), v.value.day()) .and_hms(v.value.hour(), v.value.minute(), v.value.second()) .into()), - _ => Err(Error::ArgumentsError { + _ => Err(Error::InvalidArguments { name: String::from("time::group"), message: String::from("The second argument must be a string, and can be one of 'year', 'month', 'day', 'hour', 'minute', or 'second'."), }), diff --git a/lib/src/kvs/file/mod.rs b/lib/src/kvs/file/mod.rs index 2dde8356..b3b6bc8d 100644 --- a/lib/src/kvs/file/mod.rs +++ b/lib/src/kvs/file/mod.rs @@ -33,7 +33,7 @@ impl Datastore { rw: write, tx, }), - Err(_) => Err(Error::TxError), + Err(_) => Err(Error::Tx), } } } @@ -47,7 +47,7 @@ impl Transaction { pub fn cancel(&mut self) -> Result<(), Error> { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Mark this transaction as done self.ok = true; @@ -60,11 +60,11 @@ impl Transaction { pub fn commit(&mut self) -> Result<(), Error> { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Check to see if transaction is writable if !self.rw { - return Err(Error::TxReadonlyError); + return Err(Error::TxReadonly); } // Mark this transaction as done self.ok = true; @@ -80,11 +80,11 @@ impl Transaction { { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Check to see if transaction is writable if !self.rw { - return Err(Error::TxReadonlyError); + return Err(Error::TxReadonly); } // Remove the key let res = self.tx.del(key.into())?; @@ -98,7 +98,7 @@ impl Transaction { { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Check the key let res = self.tx.exi(key.into())?; @@ -112,7 +112,7 @@ impl Transaction { { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Get the key let res = self.tx.get(key.into())?; @@ -127,11 +127,11 @@ impl Transaction { { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Check to see if transaction is writable if !self.rw { - return Err(Error::TxReadonlyError); + return Err(Error::TxReadonly); } // Set the key self.tx.set(key.into(), val.into())?; @@ -146,11 +146,11 @@ impl Transaction { { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Check to see if transaction is writable if !self.rw { - return Err(Error::TxReadonlyError); + return Err(Error::TxReadonly); } // Set the key self.tx.put(key.into(), val.into())?; @@ -164,7 +164,7 @@ impl Transaction { { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Convert the range to bytes let rng: Range = Range { diff --git a/lib/src/kvs/ixdb/mod.rs b/lib/src/kvs/ixdb/mod.rs index b882b0a9..511b7ab6 100644 --- a/lib/src/kvs/ixdb/mod.rs +++ b/lib/src/kvs/ixdb/mod.rs @@ -33,7 +33,7 @@ impl Datastore { rw: write, tx, }), - Err(_) => Err(Error::TxError), + Err(_) => Err(Error::Tx), } } } @@ -47,7 +47,7 @@ impl Transaction { pub async fn cancel(&mut self) -> Result<(), Error> { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Mark this transaction as done self.ok = true; @@ -60,11 +60,11 @@ impl Transaction { pub async fn commit(&mut self) -> Result<(), Error> { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Check to see if transaction is writable if !self.rw { - return Err(Error::TxReadonlyError); + return Err(Error::TxReadonly); } // Mark this transaction as done self.ok = true; @@ -80,11 +80,11 @@ impl Transaction { { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Check to see if transaction is writable if !self.rw { - return Err(Error::TxReadonlyError); + return Err(Error::TxReadonly); } // Remove the key let res = self.tx.del(key.into()).await?; @@ -98,7 +98,7 @@ impl Transaction { { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Check the key let res = self.tx.exi(key.into()).await?; @@ -112,7 +112,7 @@ impl Transaction { { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Get the key let res = self.tx.get(key.into()).await?; @@ -127,11 +127,11 @@ impl Transaction { { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Check to see if transaction is writable if !self.rw { - return Err(Error::TxReadonlyError); + return Err(Error::TxReadonly); } // Set the key self.tx.set(key.into(), val.into()).await?; @@ -146,11 +146,11 @@ impl Transaction { { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Check to see if transaction is writable if !self.rw { - return Err(Error::TxReadonlyError); + return Err(Error::TxReadonly); } // Set the key self.tx.put(key.into(), val.into()).await?; @@ -164,7 +164,7 @@ impl Transaction { { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Convert the range to bytes let rng: Range = Range { diff --git a/lib/src/kvs/mem/mod.rs b/lib/src/kvs/mem/mod.rs index d6eed308..431d5605 100644 --- a/lib/src/kvs/mem/mod.rs +++ b/lib/src/kvs/mem/mod.rs @@ -33,7 +33,7 @@ impl Datastore { rw: write, tx, }), - Err(_) => Err(Error::TxError), + Err(_) => Err(Error::Tx), } } } @@ -47,7 +47,7 @@ impl Transaction { pub fn cancel(&mut self) -> Result<(), Error> { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Mark this transaction as done self.ok = true; @@ -60,11 +60,11 @@ impl Transaction { pub fn commit(&mut self) -> Result<(), Error> { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Check to see if transaction is writable if !self.rw { - return Err(Error::TxReadonlyError); + return Err(Error::TxReadonly); } // Mark this transaction as done self.ok = true; @@ -80,11 +80,11 @@ impl Transaction { { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Check to see if transaction is writable if !self.rw { - return Err(Error::TxReadonlyError); + return Err(Error::TxReadonly); } // Remove the key let res = self.tx.del(key.into())?; @@ -98,7 +98,7 @@ impl Transaction { { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Check the key let res = self.tx.exi(key.into())?; @@ -112,7 +112,7 @@ impl Transaction { { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Get the key let res = self.tx.get(key.into())?; @@ -127,11 +127,11 @@ impl Transaction { { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Check to see if transaction is writable if !self.rw { - return Err(Error::TxReadonlyError); + return Err(Error::TxReadonly); } // Set the key self.tx.set(key.into(), val.into())?; @@ -146,11 +146,11 @@ impl Transaction { { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Check to see if transaction is writable if !self.rw { - return Err(Error::TxReadonlyError); + return Err(Error::TxReadonly); } // Set the key self.tx.put(key.into(), val.into())?; @@ -164,7 +164,7 @@ impl Transaction { { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Convert the range to bytes let rng: Range = Range { diff --git a/lib/src/kvs/tikv/mod.rs b/lib/src/kvs/tikv/mod.rs index d351cdf9..282ee384 100644 --- a/lib/src/kvs/tikv/mod.rs +++ b/lib/src/kvs/tikv/mod.rs @@ -34,7 +34,7 @@ impl Datastore { rw: write, tx, }), - Err(_) => Err(Error::TxError), + Err(_) => Err(Error::Tx), }, false => match self.db.begin_pessimistic().await { Ok(tx) => Ok(Transaction { @@ -42,7 +42,7 @@ impl Datastore { rw: write, tx, }), - Err(_) => Err(Error::TxError), + Err(_) => Err(Error::Tx), }, } } @@ -57,7 +57,7 @@ impl Transaction { pub async fn cancel(&mut self) -> Result<(), Error> { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Mark this transaction as done self.ok = true; @@ -70,11 +70,11 @@ impl Transaction { pub async fn commit(&mut self) -> Result<(), Error> { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Check to see if transaction is writable if !self.rw { - return Err(Error::TxReadonlyError); + return Err(Error::TxReadonly); } // Mark this transaction as done self.ok = true; @@ -90,11 +90,11 @@ impl Transaction { { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Check to see if transaction is writable if !self.rw { - return Err(Error::TxReadonlyError); + return Err(Error::TxReadonly); } // Delete the key self.tx.delete(key.into()).await?; @@ -108,7 +108,7 @@ impl Transaction { { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Check the key let res = self.tx.key_exists(key.into()).await?; @@ -122,7 +122,7 @@ impl Transaction { { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Get the key let res = self.tx.get(key.into()).await?; @@ -137,11 +137,11 @@ impl Transaction { { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Check to see if transaction is writable if !self.rw { - return Err(Error::TxReadonlyError); + return Err(Error::TxReadonly); } // Set the key self.tx.put(key.into(), val.into()).await?; @@ -156,11 +156,11 @@ impl Transaction { { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Check to see if transaction is writable if !self.rw { - return Err(Error::TxReadonlyError); + return Err(Error::TxReadonly); } // Set the key self.tx.insert(key.into(), val.into()).await?; @@ -174,7 +174,7 @@ impl Transaction { { // Check to see if transaction is closed if self.ok { - return Err(Error::TxFinishedError); + return Err(Error::TxFinished); } // Convert the range to bytes let rng: Range = Range { diff --git a/lib/src/sql/array.rs b/lib/src/sql/array.rs index daeedaa0..ab42fbbe 100644 --- a/lib/src/sql/array.rs +++ b/lib/src/sql/array.rs @@ -108,7 +108,7 @@ impl Array { .iter() .map(|v| match v { Value::Object(v) => v.to_operation(), - _ => Err(Error::PatchError { + _ => Err(Error::InvalidPatch { message: String::from("Operation must be an object"), }), }) diff --git a/lib/src/sql/object.rs b/lib/src/sql/object.rs index 9c892fde..8edbd0f1 100644 --- a/lib/src/sql/object.rs +++ b/lib/src/sql/object.rs @@ -78,11 +78,11 @@ impl Object { None => Value::Null, }, }), - _ => Err(Error::PatchError { + _ => Err(Error::InvalidPatch { message: String::from("'path' key missing"), }), }, - _ => Err(Error::PatchError { + _ => Err(Error::InvalidPatch { message: String::from("'op' key missing"), }), } diff --git a/lib/src/sql/parser.rs b/lib/src/sql/parser.rs index bb56999c..e45cf2b3 100644 --- a/lib/src/sql/parser.rs +++ b/lib/src/sql/parser.rs @@ -8,32 +8,32 @@ use std::str; pub fn parse(input: &str) -> Result { match input.trim().len() { - 0 => Err(Error::EmptyError), + 0 => Err(Error::QueryEmpty), _ => match query(input) { Ok((_, query)) => Ok(query), Err(Err::Error(e)) => match e { ParserError(e) => { let (s, l, c) = locate(input, e); - Err(Error::ParseError { + Err(Error::InvalidQuery { line: l, char: c, sql: s.to_string(), }) } - ScriptError(e) => Err(Error::LanguageError { + ScriptError(e) => Err(Error::InvalidScript { message: e, }), }, Err(Err::Failure(e)) => match e { ParserError(e) => { let (s, l, c) = locate(input, e); - Err(Error::ParseError { + Err(Error::InvalidQuery { line: l, char: c, sql: s.to_string(), }) } - ScriptError(e) => Err(Error::LanguageError { + ScriptError(e) => Err(Error::InvalidScript { message: e, }), }, @@ -44,32 +44,32 @@ pub fn parse(input: &str) -> Result { pub fn json(input: &str) -> Result { match input.trim().len() { - 0 => Err(Error::EmptyError), + 0 => Err(Error::QueryEmpty), _ => match value(input) { Ok((_, query)) => Ok(query), Err(Err::Error(e)) => match e { ParserError(e) => { let (s, l, c) = locate(input, e); - Err(Error::ParseError { + Err(Error::InvalidQuery { line: l, char: c, sql: s.to_string(), }) } - ScriptError(e) => Err(Error::LanguageError { + ScriptError(e) => Err(Error::InvalidScript { message: e, }), }, Err(Err::Failure(e)) => match e { ParserError(e) => { let (s, l, c) = locate(input, e); - Err(Error::ParseError { + Err(Error::InvalidQuery { line: l, char: c, sql: s.to_string(), }) } - ScriptError(e) => Err(Error::LanguageError { + ScriptError(e) => Err(Error::InvalidScript { message: e, }), }, diff --git a/lib/src/sql/statements/create.rs b/lib/src/sql/statements/create.rs index 507d6355..de2df279 100644 --- a/lib/src/sql/statements/create.rs +++ b/lib/src/sql/statements/create.rs @@ -52,7 +52,7 @@ impl CreateStatement { Value::Model(_) => i.prepare(v), Value::Array(_) => i.prepare(v), v => { - return Err(Error::CreateStatementError { + return Err(Error::CreateStatement { value: v, }) } diff --git a/lib/src/sql/statements/delete.rs b/lib/src/sql/statements/delete.rs index eee4872b..ce70c081 100644 --- a/lib/src/sql/statements/delete.rs +++ b/lib/src/sql/statements/delete.rs @@ -53,7 +53,7 @@ impl DeleteStatement { Value::Model(_) => i.prepare(v), Value::Array(_) => i.prepare(v), v => { - return Err(Error::DeleteStatementError { + return Err(Error::DeleteStatement { value: v, }) } diff --git a/lib/src/sql/statements/insert.rs b/lib/src/sql/statements/insert.rs index ebb30131..eea2d70c 100644 --- a/lib/src/sql/statements/insert.rs +++ b/lib/src/sql/statements/insert.rs @@ -58,7 +58,7 @@ impl InsertStatement { Value::Array(v) => v.value.into_iter().for_each(|v| i.prepare(v)), Value::Object(_) => i.prepare(v), v => { - return Err(Error::InsertStatementError { + return Err(Error::InsertStatement { value: v, }) } diff --git a/lib/src/sql/statements/relate.rs b/lib/src/sql/statements/relate.rs index 76817dd8..4979df02 100644 --- a/lib/src/sql/statements/relate.rs +++ b/lib/src/sql/statements/relate.rs @@ -59,7 +59,7 @@ impl RelateStatement { Value::Model(_) => i.prepare(v), Value::Array(_) => i.prepare(v), v => { - return Err(Error::RelateStatementError { + return Err(Error::RelateStatement { value: v, }) } diff --git a/lib/src/sql/statements/update.rs b/lib/src/sql/statements/update.rs index 713cea5d..7dd6e4bb 100644 --- a/lib/src/sql/statements/update.rs +++ b/lib/src/sql/statements/update.rs @@ -54,7 +54,7 @@ impl UpdateStatement { Value::Model(_) => i.prepare(v), Value::Array(_) => i.prepare(v), v => { - return Err(Error::UpdateStatementError { + return Err(Error::UpdateStatement { value: v, }) }