Convert error names according to clippy recommendations
This commit is contained in:
parent
e8d423f8d6
commit
77844ab06b
28 changed files with 174 additions and 163 deletions
|
@ -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<Reason> for Error {
|
||||
fn from(reason: Reason) -> Error {
|
||||
match reason {
|
||||
Reason::Timedout => Error::TimeoutError,
|
||||
Reason::Canceled => Error::CancelledError,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Reason> for io::Error {
|
||||
fn from(reason: Reason) -> Self {
|
||||
let kind = match reason {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -300,7 +300,7 @@ impl Iterator {
|
|||
fn result(&mut self, res: Result<Value, Error>) {
|
||||
// Process the result
|
||||
match res {
|
||||
Err(Error::IgnoreError) => {
|
||||
Err(Error::Ignore) => {
|
||||
return;
|
||||
}
|
||||
Err(e) => {
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
@ -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!(),
|
||||
|
|
|
@ -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(()),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(()),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<Thing>, Value)>),
|
||||
Tokio(#[from] TokioError<(Option<Thing>, Value)>),
|
||||
}
|
||||
|
|
|
@ -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."),
|
||||
}),
|
||||
|
|
|
@ -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."),
|
||||
}),
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::sql::value::Value;
|
|||
pub async fn head(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
|
||||
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<Value>) -> Result<Value, Error> {
|
|||
pub async fn get(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
|
||||
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<Value>) -> Result<Value, Error> {
|
|||
pub async fn put(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
|
||||
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<Value>) -> Result<Value, Error> {
|
|||
pub async fn post(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
|
||||
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<Value>) -> Result<Value, Error> {
|
|||
pub async fn patch(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
|
||||
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<Value>) -> Result<Value, Error> {
|
|||
pub async fn delete(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
|
||||
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."),
|
||||
}),
|
||||
|
|
|
@ -38,7 +38,7 @@ pub fn fixed(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
|
|||
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."),
|
||||
}),
|
||||
|
|
|
@ -91,12 +91,12 @@ pub fn string(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
|
|||
.map(char::from)
|
||||
.collect::<String>()
|
||||
.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<Value>) -> Result<Value, Error> {
|
|||
.map(char::from)
|
||||
.collect::<String>()
|
||||
.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."),
|
||||
}),
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::sql::script::Script;
|
|||
use crate::sql::value::Value;
|
||||
|
||||
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."),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
.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'."),
|
||||
}),
|
||||
|
|
|
@ -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<Key> = Range {
|
||||
|
|
|
@ -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<Key> = Range {
|
||||
|
|
|
@ -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<Key> = Range {
|
||||
|
|
|
@ -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<Key> = Range {
|
||||
|
|
|
@ -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"),
|
||||
}),
|
||||
})
|
||||
|
|
|
@ -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"),
|
||||
}),
|
||||
}
|
||||
|
|
|
@ -8,32 +8,32 @@ use std::str;
|
|||
|
||||
pub fn parse(input: &str) -> Result<Query, Error> {
|
||||
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<Query, Error> {
|
|||
|
||||
pub fn json(input: &str) -> Result<Value, Error> {
|
||||
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,
|
||||
}),
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue