Skip to content

Commit

Permalink
Improve collection/config deserialization errors
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasPickering committed Dec 2, 2024
1 parent a0b5a7e commit 6f597f9
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
### Changes

- Wrap long error messages in response pane
- Include data path in config/collection deserialization errors
- This should make errors much less cryptic and frustrating

## [2.3.0] - 2024-11-11

Expand Down
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ rusqlite_migration = "1.2.0"
serde = {workspace = true, features = ["derive"]}
serde_json = {workspace = true}
serde_json_path = {workspace = true}
serde_path_to_error = "0.1.16"
serde_yaml = {workspace = true}
strum = {workspace = true, features = ["derive"]}
thiserror = {workspace = true}
Expand Down
3 changes: 3 additions & 0 deletions crates/core/src/collection/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ impl crate::test_util::Factory for Profile {
Serialize,
Deserialize,
)]
#[serde(transparent)]
pub struct ProfileId(String);

#[cfg(any(test, feature = "test"))]
Expand Down Expand Up @@ -235,6 +236,7 @@ pub struct Recipe {
Serialize,
Deserialize,
)]
#[serde(transparent)]
pub struct RecipeId(String);

#[cfg(any(test, feature = "test"))]
Expand Down Expand Up @@ -412,6 +414,7 @@ pub struct Chain {
Serialize,
Deserialize,
)]
#[serde(transparent)]
#[cfg_attr(test, derive(proptest_derive::Arbitrary))]
pub struct ChainId(#[deref(forward)] Identifier);

Expand Down
1 change: 1 addition & 0 deletions crates/core/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ impl From<serde_json::Value> for Template {
Serialize,
Deserialize,
)]
#[serde(transparent)]
#[cfg_attr(test, derive(proptest_derive::Arbitrary))]
pub struct Identifier(
#[cfg_attr(test, proptest(regex = "[a-zA-Z0-9-_]+"))] String,
Expand Down
11 changes: 6 additions & 5 deletions crates/core/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ pub fn doc_link(path: &str) -> String {
}

/// Parse bytes from a reader into YAML. This will merge any anchors/aliases.
pub fn parse_yaml<T: DeserializeOwned>(
reader: impl Read,
) -> serde_yaml::Result<T> {
pub fn parse_yaml<T: DeserializeOwned>(reader: impl Read) -> anyhow::Result<T> {
// Two-step parsing is required for anchor/alias merging
let mut yaml_value: serde_yaml::Value = serde_yaml::from_reader(reader)?;
let deserializer = serde_yaml::Deserializer::from_reader(reader);
let mut yaml_value: serde_yaml::Value =
serde_path_to_error::deserialize(deserializer)?;
yaml_value.apply_merge()?;
serde_yaml::from_value(yaml_value)
let output = serde_path_to_error::deserialize(yaml_value)?;
Ok(output)
}

/// Format a datetime for the user
Expand Down

0 comments on commit 6f597f9

Please sign in to comment.