Skip to content

Commit 46812d0

Browse files
committed
wip
1 parent 023cb9e commit 46812d0

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

rust/catalyst-types/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ uuid = { version = "1.12.0", features = ["v4", "v7", "serde"] }
2929
chrono = "0.4.39"
3030
tracing = "0.1.41"
3131
strum = { version = "0.27.1", features = ["derive"] }
32-
anyhow = "1.0.95"
3332
jsonschema = "0.28.3"
3433
serde_json = { version = "1.0.134", features = ["raw_value"] }
3534

rust/catalyst-types/src/json_schema.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use std::{ops::Deref, sync::Arc};
44

5-
use anyhow::anyhow;
65
use jsonschema::{options, Draft, Validator};
76
use serde_json::Value;
87

@@ -14,6 +13,19 @@ use serde_json::Value;
1413
#[derive(Clone)]
1514
pub struct JsonSchema(Arc<Validator>);
1615

16+
/// `JsonSchema` building error type.
17+
#[derive(Debug, thiserror::Error)]
18+
pub enum SchemaBuildError {
19+
/// Invalid JSON Schema error.
20+
#[error("Invalid JSON Schema")]
21+
InvalidSchema,
22+
/// Undetectable JSON schema version.
23+
#[error(
24+
"Could not detect draft version and schema is not valid against Draft2020-12 or Draft7"
25+
)]
26+
UndetectableDraft,
27+
}
28+
1729
impl Deref for JsonSchema {
1830
type Target = Validator;
1931

@@ -23,7 +35,7 @@ impl Deref for JsonSchema {
2335
}
2436

2537
impl TryFrom<&Value> for JsonSchema {
26-
type Error = anyhow::Error;
38+
type Error = SchemaBuildError;
2739

2840
fn try_from(schema: &Value) -> std::result::Result<Self, Self::Error> {
2941
let draft_version = if let Some(schema) = schema.get("$schema").and_then(|s| s.as_str()) {
@@ -42,7 +54,7 @@ impl TryFrom<&Value> for JsonSchema {
4254
let validator = options()
4355
.with_draft(draft)
4456
.build(schema)
45-
.map_err(|e| anyhow!("Invalid JSON Schema: {e}"))?;
57+
.map_err(|_| SchemaBuildError::InvalidSchema)?;
4658

4759
Ok(JsonSchema(validator.into()))
4860
} else {
@@ -57,9 +69,7 @@ impl TryFrom<&Value> for JsonSchema {
5769
return Ok(JsonSchema(validator.into()));
5870
}
5971

60-
Err(anyhow!(
61-
"Could not detect draft version and schema is not valid against Draft2020-12 or Draft7"
62-
))
72+
Err(SchemaBuildError::UndetectableDraft)
6373
}
6474
}
6575
}

0 commit comments

Comments
 (0)