Skip to content

Commit

Permalink
improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
freestrings committed Jun 19, 2019
1 parent 6a270c9 commit fff0e86
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 11 deletions.
Binary file removed docs/936e94ea88fa30f5750a.module.wasm
Binary file not shown.
Binary file removed docs/bench/936e94ea88fa30f5750a.module.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/bench/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Binary file added docs/bench/d60993d3a441db221b47.module.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Binary file added docs/d60993d3a441db221b47.module.wasm
Binary file not shown.
9 changes: 1 addition & 8 deletions src/parser/tokenizer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::io::Write;
use std::result::Result;

use super::path_reader::{PathReader, ReaderError};
Expand Down Expand Up @@ -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 {
Expand Down
19 changes: 18 additions & 1 deletion src/select/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::HashSet;
use std::fmt;

use array_tool::vec::{Intersect, Union};
use indexmap::IndexMap;
Expand Down Expand Up @@ -514,14 +515,30 @@ enum FilterKey {
All,
}

#[derive(Debug)]
pub enum JsonPathError {
EmptyPath,
EmptyValue,
Path(String),
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<Node>,
Expand Down

0 comments on commit fff0e86

Please sign in to comment.