chore(middleware): additional error reporting for custom predicates (#330)
* Additional error reporting for custom predicates * Code review * Typo
This commit is contained in:
parent
aeedf55bad
commit
e8468d7fa8
4 changed files with 133 additions and 44 deletions
|
|
@ -22,8 +22,13 @@ fn display_wc_map(wc_map: &[Option<Value>]) -> String {
|
|||
pub enum InnerError {
|
||||
#[error("{0} {1} is over the limit {2}")]
|
||||
MaxLength(String, usize, usize),
|
||||
#[error("{0} doesn't match {1:#}.\nWildcard map:\n{map}", map=display_wc_map(.2))]
|
||||
StatementsDontMatch(Statement, StatementTmpl, Vec<Option<Value>>),
|
||||
#[error("{0} doesn't match {1:#}.\nWildcard map:\n{map}\nInternal error: {3}", map=display_wc_map(.2))]
|
||||
StatementsDontMatch(
|
||||
Statement,
|
||||
StatementTmpl,
|
||||
Vec<Option<Value>>,
|
||||
crate::middleware::Error,
|
||||
),
|
||||
#[error("invalid arguments to {0} operation")]
|
||||
OpInvalidArgs(String),
|
||||
// Other
|
||||
|
|
@ -76,8 +81,9 @@ impl Error {
|
|||
s0: Statement,
|
||||
s1: StatementTmpl,
|
||||
wc_map: Vec<Option<Value>>,
|
||||
mid_error: crate::middleware::Error,
|
||||
) -> Self {
|
||||
new!(StatementsDontMatch(s0, s1, wc_map))
|
||||
new!(StatementsDontMatch(s0, s1, wc_map, mid_error))
|
||||
}
|
||||
pub(crate) fn max_length(obj: String, found: usize, expect: usize) -> Self {
|
||||
new!(MaxLength(obj, found, expect))
|
||||
|
|
|
|||
|
|
@ -471,11 +471,14 @@ impl MainPodBuilder {
|
|||
for (st_tmpl, st) in pred.statements.iter().zip(args.iter()) {
|
||||
let st_args = st.args();
|
||||
for (st_tmpl_arg, st_arg) in st_tmpl.args.iter().zip(&st_args) {
|
||||
if !check_st_tmpl(st_tmpl_arg, st_arg, &mut wildcard_map) {
|
||||
if let Err(st_tmpl_check_error) =
|
||||
check_st_tmpl(st_tmpl_arg, st_arg, &mut wildcard_map)
|
||||
{
|
||||
return Err(Error::statements_dont_match(
|
||||
st.clone(),
|
||||
st_tmpl.clone(),
|
||||
wildcard_map,
|
||||
st_tmpl_check_error,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue