Reduce mem size of Error enum types

This commit is contained in:
Tobie Morgan Hitchcock 2022-05-06 23:09:08 +01:00
parent 2239e4becf
commit 1e2ba72e37
12 changed files with 45 additions and 49 deletions

View file

@ -245,9 +245,7 @@ impl<'a> Executor<'a> {
let res = stm.compute(&ctx, &opt, &self.txn(), None).await; let res = stm.compute(&ctx, &opt, &self.txn(), None).await;
// Catch statement timeout // Catch statement timeout
match ctx.is_timedout() { match ctx.is_timedout() {
true => Err(Error::QueryTimeout { true => Err(Error::QueryTimedout),
timer: timeout,
}),
false => res, false => res,
} }
} }

View file

@ -82,9 +82,7 @@ impl Options {
..*self ..*self
}) })
} else { } else {
Err(Error::TooManySubqueries { Err(Error::TooManySubqueries)
limit: self.dive,
})
} }
} }

View file

@ -17,19 +17,19 @@ impl<'a> Document<'a> {
if self.id.is_none() { if self.id.is_none() {
return match stm { return match stm {
Statement::Create(_) => Err(Error::CreateStatement { Statement::Create(_) => Err(Error::CreateStatement {
value: (*self.initial).clone(), value: self.initial.to_string(),
}), }),
Statement::Update(_) => Err(Error::UpdateStatement { Statement::Update(_) => Err(Error::UpdateStatement {
value: (*self.initial).clone(), value: self.initial.to_string(),
}), }),
Statement::Relate(_) => Err(Error::RelateStatement { Statement::Relate(_) => Err(Error::RelateStatement {
value: (*self.initial).clone(), value: self.initial.to_string(),
}), }),
Statement::Delete(_) => Err(Error::DeleteStatement { Statement::Delete(_) => Err(Error::DeleteStatement {
value: (*self.initial).clone(), value: self.initial.to_string(),
}), }),
Statement::Insert(_) => Err(Error::InsertStatement { Statement::Insert(_) => Err(Error::InsertStatement {
value: (*self.initial).clone(), value: self.initial.to_string(),
}), }),
_ => unreachable!(), _ => unreachable!(),
}; };

View file

@ -19,7 +19,7 @@ impl<'a> Document<'a> {
if self.current.is_some() { if self.current.is_some() {
// The record already exists // The record already exists
return Err(Error::RecordExists { return Err(Error::RecordExists {
thing: id.clone(), thing: id.to_string(),
}); });
} }
} }

View file

@ -50,9 +50,9 @@ impl<'a> Document<'a> {
// Process the ASSERT clause // Process the ASSERT clause
if !expr.compute(&ctx, opt, txn, Some(&self.current)).await?.is_truthy() { if !expr.compute(&ctx, opt, txn, Some(&self.current)).await?.is_truthy() {
return Err(Error::FieldValue { return Err(Error::FieldValue {
value: val.clone(), value: val.to_string(),
field: fd.name.clone(), field: fd.name.clone(),
check: expr.clone(), check: expr.to_string(),
}); });
} }
} }

View file

@ -58,8 +58,8 @@ impl<'a> Document<'a> {
let key = crate::key::index::new(opt.ns(), opt.db(), &ix.what, &ix.name, n); let key = crate::key::index::new(opt.ns(), opt.db(), &ix.what, &ix.name, n);
if run.putc(key, rid, None).await.is_err() { if run.putc(key, rid, None).await.is_err() {
return Err(Error::IndexExists { return Err(Error::IndexExists {
index: ix.name.to_owned(), index: ix.name.to_string(),
thing: rid.to_owned(), thing: rid.to_string(),
}); });
} }
} }
@ -77,8 +77,8 @@ impl<'a> Document<'a> {
let key = crate::key::point::new(opt.ns(), opt.db(), &ix.what, &ix.name, n, &rid.id); let key = crate::key::point::new(opt.ns(), opt.db(), &ix.what, &ix.name, n, &rid.id);
if run.putc(key, rid, None).await.is_err() { if run.putc(key, rid, None).await.is_err() {
return Err(Error::IndexExists { return Err(Error::IndexExists {
index: ix.name.to_owned(), index: ix.name.to_string(),
thing: rid.to_owned(), thing: rid.to_string(),
}); });
} }
} }

View file

@ -3,7 +3,6 @@ use crate::sql::thing::Thing;
use crate::sql::value::Value; use crate::sql::value::Value;
use msgpack::encode::Error as SerdeError; use msgpack::encode::Error as SerdeError;
use serde::Serialize; use serde::Serialize;
use std::time::Duration;
use storekey::decode::Error as DecodeError; use storekey::decode::Error as DecodeError;
use storekey::encode::Error as EncodeError; use storekey::encode::Error as EncodeError;
use thiserror::Error; use thiserror::Error;
@ -88,17 +87,15 @@ pub enum Error {
}, },
/// The query timedout /// The query timedout
#[error("Query timeout of {timer:?} exceeded")] #[error("The query was not executed because it exceeded the timeout")]
QueryTimeout { QueryTimedout,
timer: Duration,
},
/// The query did not execute, because the transaction was cancelled /// The query did not execute, because the transaction was cancelled
#[error("Query not executed due to cancelled transaction")] #[error("The query was not executed due to a cancelled transaction")]
QueryCancelled, QueryCancelled,
/// The query did not execute, because the transaction has failed /// The query did not execute, because the transaction has failed
#[error("Query not executed due to failed transaction")] #[error("The query was not executed due to a failed transaction")]
QueryNotExecuted, QueryNotExecuted,
/// The permissions do not allow for performing the specified query /// The permissions do not allow for performing the specified query
@ -155,44 +152,41 @@ pub enum Error {
/// Too many recursive subqueries have been processed /// Too many recursive subqueries have been processed
#[error("Too many recursive subqueries have been processed")] #[error("Too many recursive subqueries have been processed")]
TooManySubqueries { TooManySubqueries,
limit: usize,
},
/// Can not execute CREATE query using the specified value /// Can not execute CREATE query using the specified value
#[error("Can not execute CREATE query using value '{value}'")] #[error("Can not execute CREATE query using value '{value}'")]
CreateStatement { CreateStatement {
value: Value, value: String,
}, },
/// Can not execute UPDATE query using the specified value /// Can not execute UPDATE query using the specified value
#[error("Can not execute UPDATE query using value '{value}'")] #[error("Can not execute UPDATE query using value '{value}'")]
UpdateStatement { UpdateStatement {
value: Value, value: String,
}, },
/// Can not execute RELATE query using the specified value /// Can not execute RELATE query using the specified value
#[error("Can not execute RELATE query using value '{value}'")] #[error("Can not execute RELATE query using value '{value}'")]
RelateStatement { RelateStatement {
value: Value, value: String,
}, },
/// Can not execute DELETE query using the specified value /// Can not execute DELETE query using the specified value
#[error("Can not execute DELETE query using value '{value}'")] #[error("Can not execute DELETE query using value '{value}'")]
DeleteStatement { DeleteStatement {
value: Value, value: String,
}, },
/// Can not execute INSERT query using the specified value /// Can not execute INSERT query using the specified value
#[error("Can not execute INSERT query using value '{value}'")] #[error("Can not execute INSERT query using value '{value}'")]
InsertStatement { InsertStatement {
value: Value, value: String,
}, },
/// The permissions do not allow this query to be run on this table /// The permissions do not allow this query to be run on this table
#[error("You don't have permission to run the `{query}` query on the `{table}` table")] #[error("You don't have permission to run this query on the `{table}` table")]
TablePermissions { TablePermissions {
query: String,
table: String, table: String,
}, },
@ -205,24 +199,28 @@ pub enum Error {
/// A database entry for the specified record already exists /// A database entry for the specified record already exists
#[error("Database record `{thing}` already exists")] #[error("Database record `{thing}` already exists")]
RecordExists { RecordExists {
thing: Thing, thing: String,
}, },
/// A database index entry for the specified record already exists /// A database index entry for the specified record already exists
#[error("Database index `{index}` already contains `{thing}`")] #[error("Database index `{index}` already contains `{thing}`")]
IndexExists { IndexExists {
index: String, index: String,
thing: Thing, thing: String,
}, },
/// The specified field did not conform to the field ASSERT clause /// The specified field did not conform to the field ASSERT clause
#[error("Found '{value}' for field '{field}' but field must conform to: {check}")] #[error("Found '{value}' for field '{field}' but field must conform to: {check}")]
FieldValue { FieldValue {
value: Value, value: String,
field: Idiom, field: Idiom,
check: Value, check: String,
}, },
/// There was an error processing a value in parallel
#[error("There was an error processing a value in parallel ")]
Channel(String),
/// Represents an underlying error with Serde encoding / decoding /// Represents an underlying error with Serde encoding / decoding
#[error("Serde error: {0}")] #[error("Serde error: {0}")]
Serde(#[from] SerdeError), Serde(#[from] SerdeError),
@ -234,11 +232,6 @@ pub enum Error {
/// Represents an error when decoding a key-value entry /// Represents an error when decoding a key-value entry
#[error("Key decoding error: {0}")] #[error("Key decoding error: {0}")]
Decode(#[from] DecodeError), Decode(#[from] DecodeError),
/// Represents an underlying error with Tokio message channels
#[cfg(feature = "parallel")]
#[error("Tokio Error: {0}")]
Tokio(#[from] TokioError<(Option<Thing>, Value)>),
} }
#[cfg(feature = "kv-echodb")] #[cfg(feature = "kv-echodb")]
@ -262,6 +255,13 @@ impl From<TiKVError> for Error {
} }
} }
#[cfg(feature = "parallel")]
impl From<TokioError<(Option<Thing>, Value)>> for Error {
fn from(e: TokioError<(Option<Thing>, Value)>) -> Error {
Error::Channel(e.to_string())
}
}
impl Serialize for Error { impl Serialize for Error {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where where

View file

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

View file

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

View file

@ -59,7 +59,7 @@ impl InsertStatement {
Value::Object(_) => i.prepare(v), Value::Object(_) => i.prepare(v),
v => { v => {
return Err(Error::InsertStatement { return Err(Error::InsertStatement {
value: v, value: v.to_string(),
}) })
} }
} }

View file

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

View file

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