diff --git a/docs/936e94ea88fa30f5750a.module.wasm b/docs/936e94ea88fa30f5750a.module.wasm deleted file mode 100644 index 7fd477f..0000000 Binary files a/docs/936e94ea88fa30f5750a.module.wasm and /dev/null differ diff --git a/docs/bench/936e94ea88fa30f5750a.module.wasm b/docs/bench/936e94ea88fa30f5750a.module.wasm deleted file mode 100644 index 7fd477f..0000000 Binary files a/docs/bench/936e94ea88fa30f5750a.module.wasm and /dev/null differ diff --git a/docs/bench/bootstrap.js b/docs/bench/bootstrap.js index 4884f06..083924d 100644 --- a/docs/bench/bootstrap.js +++ b/docs/bench/bootstrap.js @@ -198,7 +198,7 @@ /******/ promises.push(installedWasmModuleData); /******/ else { /******/ var importObject = wasmImportObjects[wasmModuleId](); -/******/ var req = fetch(__webpack_require__.p + "" + {"../all_pkg/jsonpath_wasm_bg.wasm":"936e94ea88fa30f5750a"}[wasmModuleId] + ".module.wasm"); +/******/ var req = fetch(__webpack_require__.p + "" + {"../all_pkg/jsonpath_wasm_bg.wasm":"d60993d3a441db221b47"}[wasmModuleId] + ".module.wasm"); /******/ var promise; /******/ if(importObject instanceof Promise && typeof WebAssembly.compileStreaming === 'function') { /******/ promise = Promise.all([WebAssembly.compileStreaming(req), importObject]).then(function(items) { diff --git a/docs/bench/d60993d3a441db221b47.module.wasm b/docs/bench/d60993d3a441db221b47.module.wasm new file mode 100644 index 0000000..3aab6db Binary files /dev/null and b/docs/bench/d60993d3a441db221b47.module.wasm differ diff --git a/docs/bootstrap.js b/docs/bootstrap.js index 39dac25..d96588f 100644 --- a/docs/bootstrap.js +++ b/docs/bootstrap.js @@ -198,7 +198,7 @@ /******/ promises.push(installedWasmModuleData); /******/ else { /******/ var importObject = wasmImportObjects[wasmModuleId](); -/******/ var req = fetch(__webpack_require__.p + "" + {"../all_pkg/jsonpath_wasm_bg.wasm":"936e94ea88fa30f5750a"}[wasmModuleId] + ".module.wasm"); +/******/ var req = fetch(__webpack_require__.p + "" + {"../all_pkg/jsonpath_wasm_bg.wasm":"d60993d3a441db221b47"}[wasmModuleId] + ".module.wasm"); /******/ var promise; /******/ if(importObject instanceof Promise && typeof WebAssembly.compileStreaming === 'function') { /******/ promise = Promise.all([WebAssembly.compileStreaming(req), importObject]).then(function(items) { diff --git a/docs/d60993d3a441db221b47.module.wasm b/docs/d60993d3a441db221b47.module.wasm new file mode 100644 index 0000000..3aab6db Binary files /dev/null and b/docs/d60993d3a441db221b47.module.wasm differ diff --git a/src/parser/tokenizer.rs b/src/parser/tokenizer.rs index eee9365..9aa84cd 100644 --- a/src/parser/tokenizer.rs +++ b/src/parser/tokenizer.rs @@ -1,4 +1,3 @@ -use std::io::Write; use std::result::Result; use super::path_reader::{PathReader, ReaderError}; @@ -368,13 +367,7 @@ impl<'a> TokenReader<'a> { } pub fn err_msg_with_pos(&self, pos: usize) -> String { - let mut w = Vec::new(); - writeln!(&mut w, "{}", self.origin_input).unwrap(); - writeln!(&mut w, "{}", "^".repeat(pos)).unwrap(); - match std::str::from_utf8(&w[..]) { - Ok(s) => s.to_owned(), - Err(_) => panic!("Invalid UTF-8"), - } + format!("{}\n{}", self.origin_input, "^".repeat(pos)) } pub fn err_msg(&self) -> String { diff --git a/src/select/mod.rs b/src/select/mod.rs index c2d0915..770bcaa 100644 --- a/src/select/mod.rs +++ b/src/select/mod.rs @@ -1,4 +1,5 @@ use std::collections::HashSet; +use std::fmt; use array_tool::vec::{Intersect, Union}; use indexmap::IndexMap; @@ -514,7 +515,6 @@ enum FilterKey { All, } -#[derive(Debug)] pub enum JsonPathError { EmptyPath, EmptyValue, @@ -522,6 +522,23 @@ pub enum JsonPathError { Serde(String), } +impl fmt::Debug for JsonPathError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self) + } +} + +impl fmt::Display for JsonPathError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + JsonPathError::EmptyPath => f.write_str("path not set"), + JsonPathError::EmptyValue => f.write_str("json value not set"), + JsonPathError::Path(msg) => f.write_str(&format!("path error: \n{}\n", msg)), + JsonPathError::Serde(msg) => f.write_str(&format!("serde error: \n{}\n", msg)), + } + } +} + #[derive(Debug)] pub struct Selector<'a, 'b> { node: Option,