Skip to content

Commit

Permalink
jsondocck: Parse, don't validate commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
aDotInTheVoid committed Nov 25, 2024
1 parent 15b663e commit a204534
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 262 deletions.
5 changes: 3 additions & 2 deletions src/tools/jsondocck/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ impl Cache {
}
}

pub fn value(&self) -> &Value {
&self.value
// FIXME: Make this failible, so jsonpath syntax error has line number.
pub fn select(&self, path: &str) -> Vec<&Value> {
jsonpath_lib::select(&self.value, path).unwrap()
}
}
28 changes: 3 additions & 25 deletions src/tools/jsondocck/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,7 @@
use std::error::Error;
use std::fmt;

use crate::Command;

#[derive(Debug)]
pub enum CkError {
/// A check failed. File didn't exist or failed to match the command
FailedCheck(String, Command),
/// An error triggered by some other error
Induced(Box<dyn Error>),
}

impl fmt::Display for CkError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
CkError::FailedCheck(msg, cmd) => {
write!(f, "Failed check: {} on line {}", msg, cmd.lineno)
}
CkError::Induced(err) => write!(f, "Check failed: {}", err),
}
}
}

impl<T: Error + 'static> From<T> for CkError {
fn from(err: T) -> CkError {
CkError::Induced(Box::new(err))
}
pub struct CkError {
pub message: String,
pub command: Command,
}
Loading

0 comments on commit a204534

Please sign in to comment.