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;
// Catch statement timeout
match ctx.is_timedout() {
true => Err(Error::QueryTimeout {
timer: timeout,
}),
true => Err(Error::QueryTimedout),
false => res,
}
}

View file

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

View file

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

View file

@ -19,7 +19,7 @@ impl<'a> Document<'a> {
if self.current.is_some() {
// The record already exists
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
if !expr.compute(&ctx, opt, txn, Some(&self.current)).await?.is_truthy() {
return Err(Error::FieldValue {
value: val.clone(),
value: val.to_string(),
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);
if run.putc(key, rid, None).await.is_err() {
return Err(Error::IndexExists {
index: ix.name.to_owned(),
thing: rid.to_owned(),
index: ix.name.to_string(),
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);
if run.putc(key, rid, None).await.is_err() {
return Err(Error::IndexExists {
index: ix.name.to_owned(),
thing: rid.to_owned(),
index: ix.name.to_string(),
thing: rid.to_string(),
});
}
}

View file

@ -3,7 +3,6 @@ use crate::sql::thing::Thing;
use crate::sql::value::Value;
use msgpack::encode::Error as SerdeError;
use serde::Serialize;
use std::time::Duration;
use storekey::decode::Error as DecodeError;
use storekey::encode::Error as EncodeError;
use thiserror::Error;
@ -88,17 +87,15 @@ pub enum Error {
},
/// The query timedout
#[error("Query timeout of {timer:?} exceeded")]
QueryTimeout {
timer: Duration,
},
#[error("The query was not executed because it exceeded the timeout")]
QueryTimedout,
/// 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,
/// 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,
/// The permissions do not allow for performing the specified query
@ -155,44 +152,41 @@ pub enum Error {
/// Too many recursive subqueries have been processed
#[error("Too many recursive subqueries have been processed")]
TooManySubqueries {
limit: usize,
},
TooManySubqueries,
/// Can not execute CREATE query using the specified value
#[error("Can not execute CREATE query using value '{value}'")]
CreateStatement {
value: Value,
value: String,
},
/// Can not execute UPDATE query using the specified value
#[error("Can not execute UPDATE query using value '{value}'")]
UpdateStatement {
value: Value,
value: String,
},
/// Can not execute RELATE query using the specified value
#[error("Can not execute RELATE query using value '{value}'")]
RelateStatement {
value: Value,
value: String,
},
/// Can not execute DELETE query using the specified value
#[error("Can not execute DELETE query using value '{value}'")]
DeleteStatement {
value: Value,
value: String,
},
/// Can not execute INSERT query using the specified value
#[error("Can not execute INSERT query using value '{value}'")]
InsertStatement {
value: Value,
value: String,
},
/// 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 {
query: String,
table: String,
},
@ -205,24 +199,28 @@ pub enum Error {
/// A database entry for the specified record already exists
#[error("Database record `{thing}` already exists")]
RecordExists {
thing: Thing,
thing: String,
},
/// A database index entry for the specified record already exists
#[error("Database index `{index}` already contains `{thing}`")]
IndexExists {
index: String,
thing: Thing,
thing: String,
},
/// The specified field did not conform to the field ASSERT clause
#[error("Found '{value}' for field '{field}' but field must conform to: {check}")]
FieldValue {
value: Value,
value: String,
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
#[error("Serde error: {0}")]
Serde(#[from] SerdeError),
@ -234,11 +232,6 @@ pub enum Error {
/// Represents an error when decoding a key-value entry
#[error("Key decoding error: {0}")]
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")]
@ -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 {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where

View file

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

View file

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

View file

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

View file

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

View file

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