Skip to content

Commit 8aff440

Browse files
author
meir
committed
better error message
1 parent 6a409c4 commit 8aff440

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/grammer.pest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
literal = @{(!("."|"*"|"\""|"'"|"["|"]"|"="|" "|"("|")"|"{"|"}"|"|"|"<"|">"|"!") ~ ANY)+}
1+
literal = @{(!("."|"*"|"\""|"'"|"["|"]"|"="|" "|"("|")"|"{"|"}"|"|"|"<"|">"|"!"|"$") ~ ANY)+}
22

33
string = _{"\"" ~ string_value ~ "\""}
44
string_value = @{(!("\"") ~ ANY)+}

src/json_path.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,24 @@ pub (crate) fn compile<'i>(s: &'i str) -> Result<Query<'i>, QueryCompilationErro
5858
};
5959

6060
match (positives, negatives) {
61-
(None, None) => "error occured when parsing json path.".to_string(),
62-
(Some(p), None) => format!("expected one of the following: {}.", p),
63-
(None, Some(n)) => format!("unexpected tokens found: {}.", n),
64-
(Some(p), Some(n)) => format!("expected one of the following: {}, unexpected tokens found: {}.", p, n),
61+
(None, None) => "parsing error".to_string(),
62+
(Some(p), None) => format!("expected one of the following: {}", p),
63+
(None, Some(n)) => format!("unexpected tokens found: {}", n),
64+
(Some(p), Some(n)) => format!("expected one of the following: {}, unexpected tokens found: {}", p, n),
6565
}
6666

6767
}
6868
pest::error::ErrorVariant::CustomError { ref message } => message.clone(),
6969
};
7070

71+
let final_msg = if pos == s.len() {
72+
format!("\"{} <<<<----\", {}.", s, msg)
73+
} else {
74+
format!("\"{} ---->>>> {}\", {}.", &s[..pos], &s[pos..], msg)
75+
};
7176
Err(QueryCompilationError{
7277
location: pos,
73-
message: msg,
78+
message: final_msg,
7479
})
7580
}
7681
}

0 commit comments

Comments
 (0)