Skip to content

Commit

Permalink
Rollup merge of #133478 - aDotInTheVoid:finally, r=fmease
Browse files Browse the repository at this point in the history
jsondocck: Parse, don't validate commands.

Centralizes knowledge of jsondocck syntax into the parser, so the checker doesn't need to know what the indexes are.

[Vaguely related zulip discussion](https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/jsondocck.20rewrite)

I'm very happy this is negative LoC, despite adding a big, documented enum!

r? ``@fmease``
  • Loading branch information
fmease authored Dec 10, 2024
2 parents b597d2a + e6bc427 commit 5416501
Show file tree
Hide file tree
Showing 3 changed files with 169 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 5416501

Please sign in to comment.