replace `???` with actual errors

feat/vaults
Tomáš Mládek 2022-04-02 22:12:51 +02:00
parent 1a05157a9d
commit ab345bf50b
No known key found for this signature in database
GPG Key ID: 65E225C8B3E2ED8A
1 changed files with 15 additions and 16 deletions

View File

@ -298,7 +298,7 @@ impl FromStr for Query {
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
let sexp = lexpr::from_str_custom(s, lexpr::parse::Options::new()) let sexp = lexpr::from_str_custom(s, lexpr::parse::Options::new())
.map_err(|_| QueryParseError("???".into()))?; .map_err(|e| QueryParseError(format!("failed to parse s-expression: {e}")))?;
Query::try_from(&sexp) Query::try_from(&sexp)
} }
} }
@ -311,18 +311,17 @@ impl Query {
let mut subqueries: Vec<Box<Predicate>> = vec![]; let mut subqueries: Vec<Box<Predicate>> = vec![];
match &eq.entity { match &eq.entity {
QueryComponent::Exact(q_entity) => subqueries.push(Box::new( QueryComponent::Exact(q_entity) => {
data::entity.eq(q_entity subqueries.push(Box::new(data::entity.eq(q_entity.encode().map_err(
.encode() |e| QueryParseError(format!("failed producing sql: {e}")),
.map_err(|_| QueryParseError("???".into()))?), )?)))
)), }
QueryComponent::In(q_entities) => { QueryComponent::In(q_entities) => {
let entities: Result<Vec<_>, _> = let entities: Result<Vec<_>, _> =
q_entities.iter().map(|t| t.encode()).collect(); q_entities.iter().map(|t| t.encode()).collect();
subqueries.push(Box::new( subqueries.push(Box::new(data::entity.eq_any(entities.map_err(
data::entity |e| QueryParseError(format!("failed producing sql: {e}")),
.eq_any(entities.map_err(|_| QueryParseError("???".into()))?), )?)))
))
} }
QueryComponent::Contains(q_entity) => subqueries.push(Box::new( QueryComponent::Contains(q_entity) => subqueries.push(Box::new(
data::entity_searchable.like(format!("%{}%", q_entity)), data::entity_searchable.like(format!("%{}%", q_entity)),
@ -347,11 +346,11 @@ impl Query {
EntryValue::Number(n) => { EntryValue::Number(n) => {
subqueries.push(Box::new(data::value_num.eq(*n))) subqueries.push(Box::new(data::value_num.eq(*n)))
} }
_ => subqueries.push(Box::new( _ => subqueries.push(Box::new(data::value_str.eq(
data::value_str.eq(q_value q_value.to_string().map_err(|e| {
.to_string() QueryParseError(format!("failed producing sql: {e}"))
.map_err(|_| QueryParseError("???".into()))?), })?,
)), ))),
}, },
QueryComponent::In(q_values) => { QueryComponent::In(q_values) => {
let first = q_values.first().ok_or_else(|| { let first = q_values.first().ok_or_else(|| {
@ -383,7 +382,7 @@ impl Query {
if let EntryValue::Number(_) = v { if let EntryValue::Number(_) = v {
Err(QueryParseError(format!("IN queries must not combine numeric and string values! (Found {v})"))) Err(QueryParseError(format!("IN queries must not combine numeric and string values! (Found {v})")))
} else { } else {
v.to_string().map_err(|_| QueryParseError("???".into())) v.to_string().map_err(|e| QueryParseError(format!("failed producing sql: {e}")))
} }
}) })
.collect::<Result<Vec<String>, QueryParseError>>()?, .collect::<Result<Vec<String>, QueryParseError>>()?,