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