Skip to content

Commit fff0e86

Browse files
committed
improve error message
1 parent 6a270c9 commit fff0e86

File tree

8 files changed

+21
-11
lines changed

8 files changed

+21
-11
lines changed
-330 KB
Binary file not shown.
-330 KB
Binary file not shown.

docs/bench/bootstrap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198
/******/ promises.push(installedWasmModuleData);
199199
/******/ else {
200200
/******/ var importObject = wasmImportObjects[wasmModuleId]();
201-
/******/ var req = fetch(__webpack_require__.p + "" + {"../all_pkg/jsonpath_wasm_bg.wasm":"936e94ea88fa30f5750a"}[wasmModuleId] + ".module.wasm");
201+
/******/ var req = fetch(__webpack_require__.p + "" + {"../all_pkg/jsonpath_wasm_bg.wasm":"d60993d3a441db221b47"}[wasmModuleId] + ".module.wasm");
202202
/******/ var promise;
203203
/******/ if(importObject instanceof Promise && typeof WebAssembly.compileStreaming === 'function') {
204204
/******/ promise = Promise.all([WebAssembly.compileStreaming(req), importObject]).then(function(items) {
323 KB
Binary file not shown.

docs/bootstrap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198
/******/ promises.push(installedWasmModuleData);
199199
/******/ else {
200200
/******/ var importObject = wasmImportObjects[wasmModuleId]();
201-
/******/ var req = fetch(__webpack_require__.p + "" + {"../all_pkg/jsonpath_wasm_bg.wasm":"936e94ea88fa30f5750a"}[wasmModuleId] + ".module.wasm");
201+
/******/ var req = fetch(__webpack_require__.p + "" + {"../all_pkg/jsonpath_wasm_bg.wasm":"d60993d3a441db221b47"}[wasmModuleId] + ".module.wasm");
202202
/******/ var promise;
203203
/******/ if(importObject instanceof Promise && typeof WebAssembly.compileStreaming === 'function') {
204204
/******/ promise = Promise.all([WebAssembly.compileStreaming(req), importObject]).then(function(items) {
323 KB
Binary file not shown.

src/parser/tokenizer.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::io::Write;
21
use std::result::Result;
32

43
use super::path_reader::{PathReader, ReaderError};
@@ -368,13 +367,7 @@ impl<'a> TokenReader<'a> {
368367
}
369368

370369
pub fn err_msg_with_pos(&self, pos: usize) -> String {
371-
let mut w = Vec::new();
372-
writeln!(&mut w, "{}", self.origin_input).unwrap();
373-
writeln!(&mut w, "{}", "^".repeat(pos)).unwrap();
374-
match std::str::from_utf8(&w[..]) {
375-
Ok(s) => s.to_owned(),
376-
Err(_) => panic!("Invalid UTF-8"),
377-
}
370+
format!("{}\n{}", self.origin_input, "^".repeat(pos))
378371
}
379372

380373
pub fn err_msg(&self) -> String {

src/select/mod.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::collections::HashSet;
2+
use std::fmt;
23

34
use array_tool::vec::{Intersect, Union};
45
use indexmap::IndexMap;
@@ -514,14 +515,30 @@ enum FilterKey {
514515
All,
515516
}
516517

517-
#[derive(Debug)]
518518
pub enum JsonPathError {
519519
EmptyPath,
520520
EmptyValue,
521521
Path(String),
522522
Serde(String),
523523
}
524524

525+
impl fmt::Debug for JsonPathError {
526+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
527+
write!(f, "{}", self)
528+
}
529+
}
530+
531+
impl fmt::Display for JsonPathError {
532+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
533+
match self {
534+
JsonPathError::EmptyPath => f.write_str("path not set"),
535+
JsonPathError::EmptyValue => f.write_str("json value not set"),
536+
JsonPathError::Path(msg) => f.write_str(&format!("path error: \n{}\n", msg)),
537+
JsonPathError::Serde(msg) => f.write_str(&format!("serde error: \n{}\n", msg)),
538+
}
539+
}
540+
}
541+
525542
#[derive(Debug)]
526543
pub struct Selector<'a, 'b> {
527544
node: Option<Node>,

0 commit comments

Comments
 (0)