From c47f80232b940f267719d7319c65855b93689a5d Mon Sep 17 00:00:00 2001 From: Gerald Pinder Date: Mon, 5 Feb 2024 22:01:47 -0500 Subject: [PATCH] chore: Switch back to crate format_serde_error --- Cargo.lock | 87 ++++++++++++++------------------------------ Cargo.toml | 2 +- src/module_recipe.rs | 16 +++----- src/ops.rs | 16 ++++++++ 4 files changed, 50 insertions(+), 71 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c6d91294..9381131c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -147,7 +147,7 @@ dependencies = [ "percent-encoding", "serde", "serde_json", - "serde_yaml", + "serde_yaml 0.9.30", ] [[package]] @@ -305,7 +305,7 @@ dependencies = [ "rusty-hook", "serde", "serde_json", - "serde_yaml", + "serde_yaml 0.9.30", "shadow-rs", "sigstore", "tokio", @@ -1144,14 +1144,14 @@ dependencies = [ [[package]] name = "format_serde_error" -version = "0.4.0" -source = "git+https://github.com/blue-build/format_serde_error#ef37a22531a28a8c99fe5cfdd06604ad5ab0029e" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5837b8e6a4001f99fe4746767fb7379e8510c508a843caa136cc12ed9c0bad0" dependencies = [ "colored", "serde", "serde_json", - "serde_yaml", - "toml 0.8.9", + "serde_yaml 0.8.26", "unicode-segmentation", ] @@ -2830,7 +2830,7 @@ dependencies = [ "ci_info", "getopts", "nias", - "toml 0.5.11", + "toml", ] [[package]] @@ -2998,15 +2998,6 @@ dependencies = [ "syn 2.0.48", ] -[[package]] -name = "serde_spanned" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" -dependencies = [ - "serde", -] - [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -3048,6 +3039,18 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "serde_yaml" +version = "0.8.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578a7433b776b56a35785ed5ce9a7e777ac0598aac5a6dd1b4b18a307c7fc71b" +dependencies = [ + "indexmap 1.9.3", + "ryu", + "serde", + "yaml-rust", +] + [[package]] name = "serde_yaml" version = "0.9.30" @@ -3531,40 +3534,6 @@ dependencies = [ "serde", ] -[[package]] -name = "toml" -version = "0.8.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6a4b9e8023eb94392d3dca65d717c53abc5dad49c07cb65bb8fcd87115fa325" -dependencies = [ - "serde", - "serde_spanned", - "toml_datetime", - "toml_edit", -] - -[[package]] -name = "toml_datetime" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" -dependencies = [ - "serde", -] - -[[package]] -name = "toml_edit" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" -dependencies = [ - "indexmap 2.2.1", - "serde", - "serde_spanned", - "toml_datetime", - "winnow", -] - [[package]] name = "tough" version = "0.14.0" @@ -4207,15 +4176,6 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" -[[package]] -name = "winnow" -version = "0.5.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7cad8365489051ae9f054164e459304af2e7e9bb407c958076c8bf4aef52da5" -dependencies = [ - "memchr", -] - [[package]] name = "winreg" version = "0.50.0" @@ -4255,6 +4215,15 @@ dependencies = [ "rustix", ] +[[package]] +name = "yaml-rust" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" +dependencies = [ + "linked-hash-map", +] + [[package]] name = "zerocopy" version = "0.7.32" diff --git a/Cargo.toml b/Cargo.toml index a15ffec0..248c7361 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ colorized = "1" derive_builder = "0.13" directories = "5" env_logger = "0.11" -format_serde_error = { git = "https://github.com/blue-build/format_serde_error" } +format_serde_error = "0.3.0" futures-util = { version = "0.3", optional = true } fuzzy-matcher = "0.3" indexmap = { version = "2", features = ["serde"] } diff --git a/src/module_recipe.rs b/src/module_recipe.rs index df6ed5e6..217912cc 100644 --- a/src/module_recipe.rs +++ b/src/module_recipe.rs @@ -16,7 +16,7 @@ use serde_json::Value as JsonValue; use serde_yaml::Value; use typed_builder::TypedBuilder; -use crate::ops::check_command_exists; +use crate::ops::{self, check_command_exists}; #[derive(Default, Serialize, Clone, Deserialize, Debug, TypedBuilder)] pub struct Recipe<'a> { @@ -143,7 +143,7 @@ impl<'a> Recipe<'a> { debug!("Recipe contents: {file}"); let mut recipe = - serde_yaml::from_str::(&file).map_err(|err| SerdeError::new(file, err))?; + serde_yaml::from_str::(&file).map_err(ops::serde_yaml_err(&file))?; recipe.modules_ext.modules = Module::get_modules(&recipe.modules_ext.modules); @@ -220,15 +220,9 @@ impl ModuleExt { let file = fs::read_to_string(file_path.clone())?; serde_yaml::from_str::(&file).map_or_else( - |err| -> Result { - error!( - "Failed to parse module from {}: {}", - file_path.display(), - SerdeError::new(file.to_owned(), err).to_string() - ); - - let module = serde_yaml::from_str::(&file) - .map_err(|err| SerdeError::new(file, err))?; + |_| -> Result { + let module = + serde_yaml::from_str::(&file).map_err(ops::serde_yaml_err(&file))?; Ok(ModuleExt::builder().modules(vec![module]).build()) }, Ok, diff --git a/src/ops.rs b/src/ops.rs index 08d1d6d1..3796d359 100644 --- a/src/ops.rs +++ b/src/ops.rs @@ -1,4 +1,5 @@ use anyhow::{anyhow, Result}; +use format_serde_error::SerdeError; use log::{debug, trace}; use std::process::Command; @@ -24,3 +25,18 @@ pub fn check_command_exists(command: &str) -> Result<()> { )) } } + +pub fn serde_yaml_err(contents: &str) -> impl Fn(serde_yaml::Error) -> SerdeError + '_ { + |err: serde_yaml::Error| { + let location = err.location(); + let location = location.as_ref(); + SerdeError::new( + contents.to_string(), + ( + err.into(), + location.map_or(0, |l| l.line()).into(), + location.map_or(0, |l| l.column()).into(), + ), + ) + } +}