Convert error names according to clippy recommendations

This commit is contained in:
Tobie Morgan Hitchcock 2022-03-06 10:58:59 +00:00
parent e8d423f8d6
commit 77844ab06b
28 changed files with 174 additions and 163 deletions

View file

@ -1,4 +1,3 @@
use crate::err::Error;
use std::fmt; use std::fmt;
use std::io; use std::io;
@ -17,15 +16,6 @@ impl fmt::Display for Reason {
} }
} }
impl From<Reason> for Error {
fn from(reason: Reason) -> Error {
match reason {
Reason::Timedout => Error::TimeoutError,
Reason::Canceled => Error::CancelledError,
}
}
}
impl From<Reason> for io::Error { impl From<Reason> for io::Error {
fn from(reason: Reason) -> Self { fn from(reason: Reason) -> Self {
let kind = match reason { let kind = match reason {

View file

@ -97,7 +97,7 @@ impl Executor {
sql: v.sql, sql: v.sql,
time: v.time, time: v.time,
status: Status::Err, status: Status::Err,
detail: Some(format!("{}", Error::QueryCancelledError)), detail: Some(format!("{}", Error::QueryCancelled)),
result: None, result: None,
} }
} }
@ -109,7 +109,7 @@ impl Executor {
time: v.time, time: v.time,
status: Status::Err, status: Status::Err,
detail: match v.status { detail: match v.status {
Status::Ok => Some(format!("{}", Error::QueryExecutionError)), Status::Ok => Some(format!("{}", Error::QueryNotExecuted)),
Status::Err => v.detail, Status::Err => v.detail,
}, },
result: None, result: None,
@ -182,7 +182,7 @@ impl Executor {
Auth::Ns(v) if v == ns => opt.ns = Some(Arc::new(ns.to_owned())), Auth::Ns(v) if v == ns => opt.ns = Some(Arc::new(ns.to_owned())),
_ => { _ => {
opt.ns = None; opt.ns = None;
return Err(Error::NsAuthenticationError { return Err(Error::NsNotAllowed {
ns: ns.to_owned(), ns: ns.to_owned(),
}); });
} }
@ -196,7 +196,7 @@ impl Executor {
Auth::Db(_, v) if v == db => opt.db = Some(Arc::new(db.to_owned())), Auth::Db(_, v) if v == db => opt.db = Some(Arc::new(db.to_owned())),
_ => { _ => {
opt.db = None; opt.db = None;
return Err(Error::DbAuthenticationError { return Err(Error::DbNotAllowed {
db: db.to_owned(), db: db.to_owned(),
}); });
} }
@ -226,7 +226,7 @@ impl Executor {
// Process all other normal statements // Process all other normal statements
_ => match self.err { _ => match self.err {
// This transaction has failed // This transaction has failed
Some(_) => Err(Error::QueryExecutionError), Some(_) => Err(Error::QueryNotExecuted),
// Compute the statement normally // Compute the statement normally
None => { None => {
// Create a transaction // Create a transaction
@ -244,7 +244,7 @@ impl Executor {
// Catch statement timeout // Catch statement timeout
let res = match stm.timeout() { let res = match stm.timeout() {
Some(timeout) => match ctx.is_timedout() { Some(timeout) => match ctx.is_timedout() {
true => Err(Error::QueryTimeoutError { true => Err(Error::QueryTimeout {
timer: timeout, timer: timeout,
}), }),
false => res, false => res,

View file

@ -300,7 +300,7 @@ impl Iterator {
fn result(&mut self, res: Result<Value, Error>) { fn result(&mut self, res: Result<Value, Error>) {
// Process the result // Process the result
match res { match res {
Err(Error::IgnoreError) => { Err(Error::Ignore) => {
return; return;
} }
Err(e) => { Err(e) => {

View file

@ -79,7 +79,7 @@ impl Options {
..*self ..*self
}) })
} else { } else {
Err(Error::RecursiveSubqueryError { Err(Error::TooManySubqueries {
limit: self.dive, limit: self.dive,
}) })
} }
@ -167,13 +167,13 @@ impl Options {
// Check whether the authentication permissions are ok // Check whether the authentication permissions are ok
pub fn check(&self, level: Level) -> Result<(), Error> { pub fn check(&self, level: Level) -> Result<(), Error> {
if !self.auth.check(level) { if !self.auth.check(level) {
return Err(Error::QueryPermissionsError); return Err(Error::QueryPermissions);
} }
if self.ns.is_none() { if self.ns.is_none() {
return Err(Error::NsError); return Err(Error::NsEmpty);
} }
if self.db.is_none() { if self.db.is_none() {
return Err(Error::DbError); return Err(Error::DbEmpty);
} }
Ok(()) Ok(())
} }

View file

@ -16,19 +16,19 @@ impl<'a> Document<'a> {
match self.id { match self.id {
Some(_) => Ok(()), Some(_) => Ok(()),
None => match stm { None => match stm {
Statement::Create(_) => Err(Error::CreateStatementError { Statement::Create(_) => Err(Error::CreateStatement {
value: (*self.initial).clone(), value: (*self.initial).clone(),
}), }),
Statement::Update(_) => Err(Error::UpdateStatementError { Statement::Update(_) => Err(Error::UpdateStatement {
value: (*self.initial).clone(), value: (*self.initial).clone(),
}), }),
Statement::Relate(_) => Err(Error::RelateStatementError { Statement::Relate(_) => Err(Error::RelateStatement {
value: (*self.initial).clone(), value: (*self.initial).clone(),
}), }),
Statement::Delete(_) => Err(Error::DeleteStatementError { Statement::Delete(_) => Err(Error::DeleteStatement {
value: (*self.initial).clone(), value: (*self.initial).clone(),
}), }),
Statement::Insert(_) => Err(Error::InsertStatementError { Statement::Insert(_) => Err(Error::InsertStatement {
value: (*self.initial).clone(), value: (*self.initial).clone(),
}), }),
_ => unreachable!(), _ => unreachable!(),

View file

@ -24,7 +24,7 @@ impl<'a> Document<'a> {
match cond { match cond {
Some(v) => { Some(v) => {
match v.expr.compute(ctx, opt, txn, Some(&self.current)).await?.is_truthy() { match v.expr.compute(ctx, opt, txn, Some(&self.current)).await?.is_truthy() {
false => Err(Error::IgnoreError), false => Err(Error::Ignore),
true => Ok(()), true => Ok(()),
} }
} }

View file

@ -14,7 +14,7 @@ impl<'a> Document<'a> {
_stm: &Statement, _stm: &Statement,
) -> Result<(), Error> { ) -> Result<(), Error> {
match self.id.is_some() && self.current.is_none() { match self.id.is_some() && self.current.is_none() {
true => Err(Error::IgnoreError), true => Err(Error::Ignore),
false => Ok(()), false => Ok(()),
} }
} }

View file

@ -32,7 +32,7 @@ impl<'a> Document<'a> {
// Match clause // Match clause
match expr { match expr {
Some(v) => match v { Some(v) => match v {
Output::None => Err(Error::IgnoreError), Output::None => Err(Error::Ignore),
Output::Null => Ok(Value::Null), Output::Null => Ok(Value::Null),
Output::Diff => Ok(self.initial.diff(&self.current, Idiom::default()).into()), Output::Diff => Ok(self.initial.diff(&self.current, Idiom::default()).into()),
Output::After => self.current.compute(ctx, opt, txn, Some(&self.current)).await, Output::After => self.current.compute(ctx, opt, txn, Some(&self.current)).await,

View file

@ -20,107 +20,131 @@ use tokio::sync::mpsc::error::SendError as TokioError;
#[derive(Error, Debug)] #[derive(Error, Debug)]
pub enum Error { pub enum Error {
#[error("Conditional clause is not truthy")]
Ignore,
#[error("Couldn't setup connection to underlying datastore")] #[error("Couldn't setup connection to underlying datastore")]
DsError, Ds,
#[error("Couldn't create a database transaction")] #[error("Couldn't create a database transaction")]
TxError, Tx,
#[error("Couldn't update a finished transaction")] #[error("Couldn't update a finished transaction")]
TxFinishedError, TxFinished,
#[error("Couldn't write to a read only transaction")] #[error("Couldn't write to a read only transaction")]
TxReadonlyError, TxReadonly,
#[error("Specify a namespace to use")] #[error("Specify a namespace to use")]
NsError, NsEmpty,
#[error("Specify a database to use")] #[error("Specify a database to use")]
DbError, DbEmpty,
#[error("Specify some SQL code to execute")] #[error("Specify some SQL code to execute")]
EmptyError, QueryEmpty,
#[error("The query failed to complete in time")]
TimeoutError,
#[error("The query was cancelled before completion")]
CancelledError,
#[error("Parse error on line {line} at character {char} when parsing '{sql}'")] #[error("Parse error on line {line} at character {char} when parsing '{sql}'")]
ParseError { InvalidQuery {
line: usize, line: usize,
char: usize, char: usize,
sql: String, sql: String,
}, },
#[error("The JSON Patch contains invalid operations. {message}")] #[error("The JSON Patch contains invalid operations. {message}")]
PatchError { InvalidPatch {
message: String, message: String,
}, },
#[error("Problem with embedded script function. {message}")] #[error("Problem with embedded script function. {message}")]
LanguageError { InvalidScript {
message: String, message: String,
}, },
#[error("Incorrect arguments for function {name}(). {message}")] #[error("Incorrect arguments for function {name}(). {message}")]
ArgumentsError { InvalidArguments {
name: String, name: String,
message: String, message: String,
}, },
#[error("Query timeout of {timer:?} exceeded")] #[error("Query timeout of {timer:?} exceeded")]
QueryTimeoutError { QueryTimeout {
timer: Duration, timer: Duration,
}, },
#[error("Query not executed due to cancelled transaction")] #[error("Query not executed due to cancelled transaction")]
QueryCancelledError, QueryCancelled,
#[error("Query not executed due to failed transaction")] #[error("Query not executed due to failed transaction")]
QueryExecutionError, QueryNotExecuted,
#[error("You don't have permission to perform this query type")] #[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")] #[error("You don't have permission to change to the {ns} namespace")]
NsAuthenticationError { NsNotAllowed {
ns: String, ns: String,
}, },
#[error("You don't have permission to change to the {db} database")] #[error("You don't have permission to change to the {db} database")]
DbAuthenticationError { DbNotAllowed {
db: String, 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")] #[error("Too many recursive subqueries have been set")]
RecursiveSubqueryError { TooManySubqueries {
limit: usize, limit: usize,
}, },
#[error("Can not execute CREATE query using value '{value}'")] #[error("Can not execute CREATE query using value '{value}'")]
CreateStatementError { CreateStatement {
value: Value, value: Value,
}, },
#[error("Can not execute UPDATE query using value '{value}'")] #[error("Can not execute UPDATE query using value '{value}'")]
UpdateStatementError { UpdateStatement {
value: Value, value: Value,
}, },
#[error("Can not execute RELATE query using value '{value}'")] #[error("Can not execute RELATE query using value '{value}'")]
RelateStatementError { RelateStatement {
value: Value, value: Value,
}, },
#[error("Can not execute DELETE query using value '{value}'")] #[error("Can not execute DELETE query using value '{value}'")]
DeleteStatementError { DeleteStatement {
value: Value, value: Value,
}, },
#[error("Can not execute INSERT query using value '{value}'")] #[error("Can not execute INSERT query using value '{value}'")]
InsertStatementError { InsertStatement {
value: Value, value: Value,
}, },
@ -131,46 +155,43 @@ pub enum Error {
}, },
#[error("Unable to write to the `{table}` table while setup as a view")] #[error("Unable to write to the `{table}` table while setup as a view")]
TableViewError { TableIsView {
table: String, table: String,
}, },
#[error("Database record `{thing}` already exists")] #[error("Database record `{thing}` already exists")]
RecordExistsError { RecordExists {
thing: Thing, thing: Thing,
}, },
#[error("Database index `{index}` already contains `{thing}`")] #[error("Database index `{index}` already contains `{thing}`")]
RecordIndexError { RecordIndex {
index: String, index: String,
thing: Thing, thing: Thing,
}, },
#[error("Conditional clause is not truthy")]
IgnoreError,
#[error("Serde error: {0}")] #[error("Serde error: {0}")]
SerdeError(#[from] SerdeError), Serde(#[from] SerdeError),
#[error("Key encoding error: {0}")] #[error("Key encoding error: {0}")]
EncodeError(#[from] EncodeError), Encode(#[from] EncodeError),
#[error("Key decoding error: {0}")] #[error("Key decoding error: {0}")]
DecodeError(#[from] DecodeError), Decode(#[from] DecodeError),
#[cfg(feature = "kv-echodb")] #[cfg(feature = "kv-echodb")]
#[error("Datastore error: {0}")] #[error("Datastore error: {0}")]
EchoDBError(#[from] EchoDBError), EchoDB(#[from] EchoDBError),
#[cfg(feature = "kv-indxdb")] #[cfg(feature = "kv-indxdb")]
#[error("Datastore error: {0}")] #[error("Datastore error: {0}")]
IndxDBError(#[from] IndxDBError), IndxDB(#[from] IndxDBError),
#[cfg(feature = "kv-tikv")] #[cfg(feature = "kv-tikv")]
#[error("Datastore error: {0}")] #[error("Datastore error: {0}")]
TiKVError(#[from] TiKVError), TiKV(#[from] TiKVError),
#[cfg(feature = "parallel")] #[cfg(feature = "parallel")]
#[error("Tokio Error: {0}")] #[error("Tokio Error: {0}")]
TokioError(#[from] TokioError<(Option<Thing>, Value)>), Tokio(#[from] TokioError<(Option<Thing>, Value)>),
} }

View file

@ -24,56 +24,56 @@ pub fn check(
match size { match size {
Args::None => match args.len() { Args::None => match args.len() {
0 => func(ctx, args), 0 => func(ctx, args),
_ => Err(Error::ArgumentsError { _ => Err(Error::InvalidArguments {
name: name.to_owned(), name: name.to_owned(),
message: String::from("The function does not expect any arguments."), message: String::from("The function does not expect any arguments."),
}), }),
}, },
Args::One => match args.len() { Args::One => match args.len() {
1 => func(ctx, args), 1 => func(ctx, args),
_ => Err(Error::ArgumentsError { _ => Err(Error::InvalidArguments {
name: name.to_owned(), name: name.to_owned(),
message: String::from("The function expects 1 argument."), message: String::from("The function expects 1 argument."),
}), }),
}, },
Args::Two => match args.len() { Args::Two => match args.len() {
2 => func(ctx, args), 2 => func(ctx, args),
_ => Err(Error::ArgumentsError { _ => Err(Error::InvalidArguments {
name: name.to_owned(), name: name.to_owned(),
message: String::from("The function expects 2 arguments."), message: String::from("The function expects 2 arguments."),
}), }),
}, },
Args::Three => match args.len() { Args::Three => match args.len() {
3 => func(ctx, args), 3 => func(ctx, args),
_ => Err(Error::ArgumentsError { _ => Err(Error::InvalidArguments {
name: name.to_owned(), name: name.to_owned(),
message: String::from("The function expects 3 arguments."), message: String::from("The function expects 3 arguments."),
}), }),
}, },
Args::NoneOne => match args.len() { Args::NoneOne => match args.len() {
0 | 1 => func(ctx, args), 0 | 1 => func(ctx, args),
_ => Err(Error::ArgumentsError { _ => Err(Error::InvalidArguments {
name: name.to_owned(), name: name.to_owned(),
message: String::from("The function expects 0 or 1 arguments."), message: String::from("The function expects 0 or 1 arguments."),
}), }),
}, },
Args::NoneTwo => match args.len() { Args::NoneTwo => match args.len() {
0 | 2 => func(ctx, args), 0 | 2 => func(ctx, args),
_ => Err(Error::ArgumentsError { _ => Err(Error::InvalidArguments {
name: name.to_owned(), name: name.to_owned(),
message: String::from("The function expects 0 or 2 arguments."), message: String::from("The function expects 0 or 2 arguments."),
}), }),
}, },
Args::NoneOneTwo => match args.len() { Args::NoneOneTwo => match args.len() {
0 | 1 | 2 => func(ctx, args), 0 | 1 | 2 => func(ctx, args),
_ => Err(Error::ArgumentsError { _ => Err(Error::InvalidArguments {
name: name.to_owned(), name: name.to_owned(),
message: String::from("The function expects 0, 1, or 2 arguments."), message: String::from("The function expects 0, 1, or 2 arguments."),
}), }),
}, },
Args::OneTwo => match args.len() { Args::OneTwo => match args.len() {
1 | 2 => func(ctx, args), 1 | 2 => func(ctx, args),
_ => Err(Error::ArgumentsError { _ => Err(Error::InvalidArguments {
name: name.to_owned(), name: name.to_owned(),
message: String::from("The function expects 1 or 2 arguments."), message: String::from("The function expects 1 or 2 arguments."),
}), }),

View file

@ -92,7 +92,7 @@ pub mod hash {
2 => match args.remove(0) { 2 => match args.remove(0) {
Value::Geometry(Geometry::Point(v)) => match args.remove(0).as_int() { 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()), 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"), 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."), message: String::from("The second argument must be an integer greater than 0 and less than or equal to 12."),
}), }),

View file

@ -5,7 +5,7 @@ use crate::sql::value::Value;
pub async fn head(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> { pub async fn head(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
match args.len() { match args.len() {
1 | 2 => todo!(), 1 | 2 => todo!(),
_ => Err(Error::ArgumentsError { _ => Err(Error::InvalidArguments {
name: String::from("http::head"), name: String::from("http::head"),
message: String::from("The function expects 1 or 2 arguments."), message: String::from("The function expects 1 or 2 arguments."),
}), }),
@ -15,7 +15,7 @@ pub async fn head(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
pub async fn get(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> { pub async fn get(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
match args.len() { match args.len() {
1 | 2 => todo!(), 1 | 2 => todo!(),
_ => Err(Error::ArgumentsError { _ => Err(Error::InvalidArguments {
name: String::from("http::get"), name: String::from("http::get"),
message: String::from("The function expects 1 or 2 arguments."), message: String::from("The function expects 1 or 2 arguments."),
}), }),
@ -25,7 +25,7 @@ pub async fn get(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
pub async fn put(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> { pub async fn put(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
match args.len() { match args.len() {
1 | 2 | 3 => todo!(), 1 | 2 | 3 => todo!(),
_ => Err(Error::ArgumentsError { _ => Err(Error::InvalidArguments {
name: String::from("http::put"), name: String::from("http::put"),
message: String::from("The function expects 1, 2, or 3 arguments."), message: String::from("The function expects 1, 2, or 3 arguments."),
}), }),
@ -35,7 +35,7 @@ pub async fn put(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
pub async fn post(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> { pub async fn post(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
match args.len() { match args.len() {
1 | 2 | 3 => todo!(), 1 | 2 | 3 => todo!(),
_ => Err(Error::ArgumentsError { _ => Err(Error::InvalidArguments {
name: String::from("http::post"), name: String::from("http::post"),
message: String::from("The function expects 1, 2, or 3 arguments."), message: String::from("The function expects 1, 2, or 3 arguments."),
}), }),
@ -45,7 +45,7 @@ pub async fn post(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
pub async fn patch(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> { pub async fn patch(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
match args.len() { match args.len() {
1 | 2 | 3 => todo!(), 1 | 2 | 3 => todo!(),
_ => Err(Error::ArgumentsError { _ => Err(Error::InvalidArguments {
name: String::from("http::patch"), name: String::from("http::patch"),
message: String::from("The function expects 1, 2, or 3 arguments."), message: String::from("The function expects 1, 2, or 3 arguments."),
}), }),
@ -55,7 +55,7 @@ pub async fn patch(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
pub async fn delete(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> { pub async fn delete(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
match args.len() { match args.len() {
1 | 2 => todo!(), 1 | 2 => todo!(),
_ => Err(Error::ArgumentsError { _ => Err(Error::InvalidArguments {
name: String::from("http::delete"), name: String::from("http::delete"),
message: String::from("The function expects 1 or 2 arguments."), message: String::from("The function expects 1 or 2 arguments."),
}), }),

View file

@ -38,7 +38,7 @@ pub fn fixed(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
let v = args.remove(0); let v = args.remove(0);
match args.remove(0).as_int() { match args.remove(0).as_int() {
p if p > 0 => Ok(v.as_number().fixed(p as usize).into()), p if p > 0 => Ok(v.as_number().fixed(p as usize).into()),
_ => Err(Error::ArgumentsError { _ => Err(Error::InvalidArguments {
name: String::from("math::fixed"), name: String::from("math::fixed"),
message: String::from("The second argument must be an integer greater than 0."), message: String::from("The second argument must be an integer greater than 0."),
}), }),

View file

@ -91,12 +91,12 @@ pub fn string(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
.map(char::from) .map(char::from)
.collect::<String>() .collect::<String>()
.into()), .into()),
_ => Err(Error::ArgumentsError { _ => Err(Error::InvalidArguments {
name: String::from("rand::string"), 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."), 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"), 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."), 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<Value>) -> Result<Value, Error> {
.map(char::from) .map(char::from)
.collect::<String>() .collect::<String>()
.into()), .into()),
_ => Err(Error::ArgumentsError { _ => Err(Error::InvalidArguments {
name: String::from("rand::string"), name: String::from("rand::string"),
message: String::from("To generate a string of X characters in length, the argument must be a positive number."), message: String::from("To generate a string of X characters in length, the argument must be a positive number."),
}), }),

View file

@ -4,7 +4,7 @@ use crate::sql::script::Script;
use crate::sql::value::Value; use crate::sql::value::Value;
pub fn run(_ctx: &Runtime, _expr: Script) -> Result<Value, Error> { pub fn run(_ctx: &Runtime, _expr: Script) -> Result<Value, Error> {
Err(Error::LanguageError { Err(Error::InvalidScript {
message: String::from("Embedded functions are not yet supported."), message: String::from("Embedded functions are not yet supported."),
}) })
} }

View file

@ -56,7 +56,7 @@ pub fn group(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
.ymd(v.value.year(), v.value.month(), v.value.day()) .ymd(v.value.year(), v.value.month(), v.value.day())
.and_hms(v.value.hour(), v.value.minute(), v.value.second()) .and_hms(v.value.hour(), v.value.minute(), v.value.second())
.into()), .into()),
_ => Err(Error::ArgumentsError { _ => Err(Error::InvalidArguments {
name: String::from("time::group"), 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'."), message: String::from("The second argument must be a string, and can be one of 'year', 'month', 'day', 'hour', 'minute', or 'second'."),
}), }),

View file

@ -33,7 +33,7 @@ impl Datastore {
rw: write, rw: write,
tx, tx,
}), }),
Err(_) => Err(Error::TxError), Err(_) => Err(Error::Tx),
} }
} }
} }
@ -47,7 +47,7 @@ impl Transaction {
pub fn cancel(&mut self) -> Result<(), Error> { pub fn cancel(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Mark this transaction as done // Mark this transaction as done
self.ok = true; self.ok = true;
@ -60,11 +60,11 @@ impl Transaction {
pub fn commit(&mut self) -> Result<(), Error> { pub fn commit(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Check to see if transaction is writable // Check to see if transaction is writable
if !self.rw { if !self.rw {
return Err(Error::TxReadonlyError); return Err(Error::TxReadonly);
} }
// Mark this transaction as done // Mark this transaction as done
self.ok = true; self.ok = true;
@ -80,11 +80,11 @@ impl Transaction {
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Check to see if transaction is writable // Check to see if transaction is writable
if !self.rw { if !self.rw {
return Err(Error::TxReadonlyError); return Err(Error::TxReadonly);
} }
// Remove the key // Remove the key
let res = self.tx.del(key.into())?; let res = self.tx.del(key.into())?;
@ -98,7 +98,7 @@ impl Transaction {
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Check the key // Check the key
let res = self.tx.exi(key.into())?; let res = self.tx.exi(key.into())?;
@ -112,7 +112,7 @@ impl Transaction {
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Get the key // Get the key
let res = self.tx.get(key.into())?; let res = self.tx.get(key.into())?;
@ -127,11 +127,11 @@ impl Transaction {
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Check to see if transaction is writable // Check to see if transaction is writable
if !self.rw { if !self.rw {
return Err(Error::TxReadonlyError); return Err(Error::TxReadonly);
} }
// Set the key // Set the key
self.tx.set(key.into(), val.into())?; self.tx.set(key.into(), val.into())?;
@ -146,11 +146,11 @@ impl Transaction {
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Check to see if transaction is writable // Check to see if transaction is writable
if !self.rw { if !self.rw {
return Err(Error::TxReadonlyError); return Err(Error::TxReadonly);
} }
// Set the key // Set the key
self.tx.put(key.into(), val.into())?; self.tx.put(key.into(), val.into())?;
@ -164,7 +164,7 @@ impl Transaction {
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Convert the range to bytes // Convert the range to bytes
let rng: Range<Key> = Range { let rng: Range<Key> = Range {

View file

@ -33,7 +33,7 @@ impl Datastore {
rw: write, rw: write,
tx, tx,
}), }),
Err(_) => Err(Error::TxError), Err(_) => Err(Error::Tx),
} }
} }
} }
@ -47,7 +47,7 @@ impl Transaction {
pub async fn cancel(&mut self) -> Result<(), Error> { pub async fn cancel(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Mark this transaction as done // Mark this transaction as done
self.ok = true; self.ok = true;
@ -60,11 +60,11 @@ impl Transaction {
pub async fn commit(&mut self) -> Result<(), Error> { pub async fn commit(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Check to see if transaction is writable // Check to see if transaction is writable
if !self.rw { if !self.rw {
return Err(Error::TxReadonlyError); return Err(Error::TxReadonly);
} }
// Mark this transaction as done // Mark this transaction as done
self.ok = true; self.ok = true;
@ -80,11 +80,11 @@ impl Transaction {
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Check to see if transaction is writable // Check to see if transaction is writable
if !self.rw { if !self.rw {
return Err(Error::TxReadonlyError); return Err(Error::TxReadonly);
} }
// Remove the key // Remove the key
let res = self.tx.del(key.into()).await?; let res = self.tx.del(key.into()).await?;
@ -98,7 +98,7 @@ impl Transaction {
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Check the key // Check the key
let res = self.tx.exi(key.into()).await?; let res = self.tx.exi(key.into()).await?;
@ -112,7 +112,7 @@ impl Transaction {
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Get the key // Get the key
let res = self.tx.get(key.into()).await?; let res = self.tx.get(key.into()).await?;
@ -127,11 +127,11 @@ impl Transaction {
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Check to see if transaction is writable // Check to see if transaction is writable
if !self.rw { if !self.rw {
return Err(Error::TxReadonlyError); return Err(Error::TxReadonly);
} }
// Set the key // Set the key
self.tx.set(key.into(), val.into()).await?; self.tx.set(key.into(), val.into()).await?;
@ -146,11 +146,11 @@ impl Transaction {
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Check to see if transaction is writable // Check to see if transaction is writable
if !self.rw { if !self.rw {
return Err(Error::TxReadonlyError); return Err(Error::TxReadonly);
} }
// Set the key // Set the key
self.tx.put(key.into(), val.into()).await?; self.tx.put(key.into(), val.into()).await?;
@ -164,7 +164,7 @@ impl Transaction {
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Convert the range to bytes // Convert the range to bytes
let rng: Range<Key> = Range { let rng: Range<Key> = Range {

View file

@ -33,7 +33,7 @@ impl Datastore {
rw: write, rw: write,
tx, tx,
}), }),
Err(_) => Err(Error::TxError), Err(_) => Err(Error::Tx),
} }
} }
} }
@ -47,7 +47,7 @@ impl Transaction {
pub fn cancel(&mut self) -> Result<(), Error> { pub fn cancel(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Mark this transaction as done // Mark this transaction as done
self.ok = true; self.ok = true;
@ -60,11 +60,11 @@ impl Transaction {
pub fn commit(&mut self) -> Result<(), Error> { pub fn commit(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Check to see if transaction is writable // Check to see if transaction is writable
if !self.rw { if !self.rw {
return Err(Error::TxReadonlyError); return Err(Error::TxReadonly);
} }
// Mark this transaction as done // Mark this transaction as done
self.ok = true; self.ok = true;
@ -80,11 +80,11 @@ impl Transaction {
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Check to see if transaction is writable // Check to see if transaction is writable
if !self.rw { if !self.rw {
return Err(Error::TxReadonlyError); return Err(Error::TxReadonly);
} }
// Remove the key // Remove the key
let res = self.tx.del(key.into())?; let res = self.tx.del(key.into())?;
@ -98,7 +98,7 @@ impl Transaction {
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Check the key // Check the key
let res = self.tx.exi(key.into())?; let res = self.tx.exi(key.into())?;
@ -112,7 +112,7 @@ impl Transaction {
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Get the key // Get the key
let res = self.tx.get(key.into())?; let res = self.tx.get(key.into())?;
@ -127,11 +127,11 @@ impl Transaction {
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Check to see if transaction is writable // Check to see if transaction is writable
if !self.rw { if !self.rw {
return Err(Error::TxReadonlyError); return Err(Error::TxReadonly);
} }
// Set the key // Set the key
self.tx.set(key.into(), val.into())?; self.tx.set(key.into(), val.into())?;
@ -146,11 +146,11 @@ impl Transaction {
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Check to see if transaction is writable // Check to see if transaction is writable
if !self.rw { if !self.rw {
return Err(Error::TxReadonlyError); return Err(Error::TxReadonly);
} }
// Set the key // Set the key
self.tx.put(key.into(), val.into())?; self.tx.put(key.into(), val.into())?;
@ -164,7 +164,7 @@ impl Transaction {
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Convert the range to bytes // Convert the range to bytes
let rng: Range<Key> = Range { let rng: Range<Key> = Range {

View file

@ -34,7 +34,7 @@ impl Datastore {
rw: write, rw: write,
tx, tx,
}), }),
Err(_) => Err(Error::TxError), Err(_) => Err(Error::Tx),
}, },
false => match self.db.begin_pessimistic().await { false => match self.db.begin_pessimistic().await {
Ok(tx) => Ok(Transaction { Ok(tx) => Ok(Transaction {
@ -42,7 +42,7 @@ impl Datastore {
rw: write, rw: write,
tx, tx,
}), }),
Err(_) => Err(Error::TxError), Err(_) => Err(Error::Tx),
}, },
} }
} }
@ -57,7 +57,7 @@ impl Transaction {
pub async fn cancel(&mut self) -> Result<(), Error> { pub async fn cancel(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Mark this transaction as done // Mark this transaction as done
self.ok = true; self.ok = true;
@ -70,11 +70,11 @@ impl Transaction {
pub async fn commit(&mut self) -> Result<(), Error> { pub async fn commit(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Check to see if transaction is writable // Check to see if transaction is writable
if !self.rw { if !self.rw {
return Err(Error::TxReadonlyError); return Err(Error::TxReadonly);
} }
// Mark this transaction as done // Mark this transaction as done
self.ok = true; self.ok = true;
@ -90,11 +90,11 @@ impl Transaction {
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Check to see if transaction is writable // Check to see if transaction is writable
if !self.rw { if !self.rw {
return Err(Error::TxReadonlyError); return Err(Error::TxReadonly);
} }
// Delete the key // Delete the key
self.tx.delete(key.into()).await?; self.tx.delete(key.into()).await?;
@ -108,7 +108,7 @@ impl Transaction {
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Check the key // Check the key
let res = self.tx.key_exists(key.into()).await?; let res = self.tx.key_exists(key.into()).await?;
@ -122,7 +122,7 @@ impl Transaction {
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Get the key // Get the key
let res = self.tx.get(key.into()).await?; let res = self.tx.get(key.into()).await?;
@ -137,11 +137,11 @@ impl Transaction {
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Check to see if transaction is writable // Check to see if transaction is writable
if !self.rw { if !self.rw {
return Err(Error::TxReadonlyError); return Err(Error::TxReadonly);
} }
// Set the key // Set the key
self.tx.put(key.into(), val.into()).await?; self.tx.put(key.into(), val.into()).await?;
@ -156,11 +156,11 @@ impl Transaction {
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Check to see if transaction is writable // Check to see if transaction is writable
if !self.rw { if !self.rw {
return Err(Error::TxReadonlyError); return Err(Error::TxReadonly);
} }
// Set the key // Set the key
self.tx.insert(key.into(), val.into()).await?; self.tx.insert(key.into(), val.into()).await?;
@ -174,7 +174,7 @@ impl Transaction {
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.ok { if self.ok {
return Err(Error::TxFinishedError); return Err(Error::TxFinished);
} }
// Convert the range to bytes // Convert the range to bytes
let rng: Range<Key> = Range { let rng: Range<Key> = Range {

View file

@ -108,7 +108,7 @@ impl Array {
.iter() .iter()
.map(|v| match v { .map(|v| match v {
Value::Object(v) => v.to_operation(), Value::Object(v) => v.to_operation(),
_ => Err(Error::PatchError { _ => Err(Error::InvalidPatch {
message: String::from("Operation must be an object"), message: String::from("Operation must be an object"),
}), }),
}) })

View file

@ -78,11 +78,11 @@ impl Object {
None => Value::Null, None => Value::Null,
}, },
}), }),
_ => Err(Error::PatchError { _ => Err(Error::InvalidPatch {
message: String::from("'path' key missing"), message: String::from("'path' key missing"),
}), }),
}, },
_ => Err(Error::PatchError { _ => Err(Error::InvalidPatch {
message: String::from("'op' key missing"), message: String::from("'op' key missing"),
}), }),
} }

View file

@ -8,32 +8,32 @@ use std::str;
pub fn parse(input: &str) -> Result<Query, Error> { pub fn parse(input: &str) -> Result<Query, Error> {
match input.trim().len() { match input.trim().len() {
0 => Err(Error::EmptyError), 0 => Err(Error::QueryEmpty),
_ => match query(input) { _ => match query(input) {
Ok((_, query)) => Ok(query), Ok((_, query)) => Ok(query),
Err(Err::Error(e)) => match e { Err(Err::Error(e)) => match e {
ParserError(e) => { ParserError(e) => {
let (s, l, c) = locate(input, e); let (s, l, c) = locate(input, e);
Err(Error::ParseError { Err(Error::InvalidQuery {
line: l, line: l,
char: c, char: c,
sql: s.to_string(), sql: s.to_string(),
}) })
} }
ScriptError(e) => Err(Error::LanguageError { ScriptError(e) => Err(Error::InvalidScript {
message: e, message: e,
}), }),
}, },
Err(Err::Failure(e)) => match e { Err(Err::Failure(e)) => match e {
ParserError(e) => { ParserError(e) => {
let (s, l, c) = locate(input, e); let (s, l, c) = locate(input, e);
Err(Error::ParseError { Err(Error::InvalidQuery {
line: l, line: l,
char: c, char: c,
sql: s.to_string(), sql: s.to_string(),
}) })
} }
ScriptError(e) => Err(Error::LanguageError { ScriptError(e) => Err(Error::InvalidScript {
message: e, message: e,
}), }),
}, },
@ -44,32 +44,32 @@ pub fn parse(input: &str) -> Result<Query, Error> {
pub fn json(input: &str) -> Result<Value, Error> { pub fn json(input: &str) -> Result<Value, Error> {
match input.trim().len() { match input.trim().len() {
0 => Err(Error::EmptyError), 0 => Err(Error::QueryEmpty),
_ => match value(input) { _ => match value(input) {
Ok((_, query)) => Ok(query), Ok((_, query)) => Ok(query),
Err(Err::Error(e)) => match e { Err(Err::Error(e)) => match e {
ParserError(e) => { ParserError(e) => {
let (s, l, c) = locate(input, e); let (s, l, c) = locate(input, e);
Err(Error::ParseError { Err(Error::InvalidQuery {
line: l, line: l,
char: c, char: c,
sql: s.to_string(), sql: s.to_string(),
}) })
} }
ScriptError(e) => Err(Error::LanguageError { ScriptError(e) => Err(Error::InvalidScript {
message: e, message: e,
}), }),
}, },
Err(Err::Failure(e)) => match e { Err(Err::Failure(e)) => match e {
ParserError(e) => { ParserError(e) => {
let (s, l, c) = locate(input, e); let (s, l, c) = locate(input, e);
Err(Error::ParseError { Err(Error::InvalidQuery {
line: l, line: l,
char: c, char: c,
sql: s.to_string(), sql: s.to_string(),
}) })
} }
ScriptError(e) => Err(Error::LanguageError { ScriptError(e) => Err(Error::InvalidScript {
message: e, message: e,
}), }),
}, },

View file

@ -52,7 +52,7 @@ impl CreateStatement {
Value::Model(_) => i.prepare(v), Value::Model(_) => i.prepare(v),
Value::Array(_) => i.prepare(v), Value::Array(_) => i.prepare(v),
v => { v => {
return Err(Error::CreateStatementError { return Err(Error::CreateStatement {
value: v, value: v,
}) })
} }

View file

@ -53,7 +53,7 @@ impl DeleteStatement {
Value::Model(_) => i.prepare(v), Value::Model(_) => i.prepare(v),
Value::Array(_) => i.prepare(v), Value::Array(_) => i.prepare(v),
v => { v => {
return Err(Error::DeleteStatementError { return Err(Error::DeleteStatement {
value: v, value: v,
}) })
} }

View file

@ -58,7 +58,7 @@ impl InsertStatement {
Value::Array(v) => v.value.into_iter().for_each(|v| i.prepare(v)), Value::Array(v) => v.value.into_iter().for_each(|v| i.prepare(v)),
Value::Object(_) => i.prepare(v), Value::Object(_) => i.prepare(v),
v => { v => {
return Err(Error::InsertStatementError { return Err(Error::InsertStatement {
value: v, value: v,
}) })
} }

View file

@ -59,7 +59,7 @@ impl RelateStatement {
Value::Model(_) => i.prepare(v), Value::Model(_) => i.prepare(v),
Value::Array(_) => i.prepare(v), Value::Array(_) => i.prepare(v),
v => { v => {
return Err(Error::RelateStatementError { return Err(Error::RelateStatement {
value: v, value: v,
}) })
} }

View file

@ -54,7 +54,7 @@ impl UpdateStatement {
Value::Model(_) => i.prepare(v), Value::Model(_) => i.prepare(v),
Value::Array(_) => i.prepare(v), Value::Array(_) => i.prepare(v),
v => { v => {
return Err(Error::UpdateStatementError { return Err(Error::UpdateStatement {
value: v, value: v,
}) })
} }