Skip to content

Commit 0ce4667

Browse files
authored
Unrolled build for rust-lang#133478
Rollup merge of rust-lang#133478 - aDotInTheVoid:finally, r=fmease 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``
2 parents 4996052 + e6bc427 commit 0ce4667

File tree

3 files changed

+169
-262
lines changed

3 files changed

+169
-262
lines changed

src/tools/jsondocck/src/cache.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ impl Cache {
2828
}
2929
}
3030

31-
pub fn value(&self) -> &Value {
32-
&self.value
31+
// FIXME: Make this failible, so jsonpath syntax error has line number.
32+
pub fn select(&self, path: &str) -> Vec<&Value> {
33+
jsonpath_lib::select(&self.value, path).unwrap()
3334
}
3435
}

src/tools/jsondocck/src/error.rs

+3-25
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,7 @@
1-
use std::error::Error;
2-
use std::fmt;
3-
41
use crate::Command;
52

63
#[derive(Debug)]
7-
pub enum CkError {
8-
/// A check failed. File didn't exist or failed to match the command
9-
FailedCheck(String, Command),
10-
/// An error triggered by some other error
11-
Induced(Box<dyn Error>),
12-
}
13-
14-
impl fmt::Display for CkError {
15-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16-
match self {
17-
CkError::FailedCheck(msg, cmd) => {
18-
write!(f, "Failed check: {} on line {}", msg, cmd.lineno)
19-
}
20-
CkError::Induced(err) => write!(f, "Check failed: {}", err),
21-
}
22-
}
23-
}
24-
25-
impl<T: Error + 'static> From<T> for CkError {
26-
fn from(err: T) -> CkError {
27-
CkError::Induced(Box::new(err))
28-
}
4+
pub struct CkError {
5+
pub message: String,
6+
pub command: Command,
297
}

0 commit comments

Comments
 (0)