diff --git a/rust/migrate-wicked/Cargo.lock b/rust/migrate-wicked/Cargo.lock index 123e90de76..869a79b190 100644 --- a/rust/migrate-wicked/Cargo.lock +++ b/rust/migrate-wicked/Cargo.lock @@ -1905,6 +1905,7 @@ dependencies = [ "serde", "serde_ignored", "serde_json", + "serde_path_to_error", "serde_with", "serde_yaml", "simplelog", diff --git a/rust/migrate-wicked/Cargo.toml b/rust/migrate-wicked/Cargo.toml index 3eb00e4236..6a411b2c3a 100644 --- a/rust/migrate-wicked/Cargo.toml +++ b/rust/migrate-wicked/Cargo.toml @@ -26,6 +26,7 @@ serde_ignored = "0.1.9" uuid = { version = "1.3.4", features = ["v4"] } macaddr = "1.0" dotenv = "0.15.0" +serde_path_to_error = "0.1.16" [[bin]] name = "migrate-wicked" diff --git a/rust/migrate-wicked/src/main.rs b/rust/migrate-wicked/src/main.rs index 88efdd3543..6abd0c1eba 100644 --- a/rust/migrate-wicked/src/main.rs +++ b/rust/migrate-wicked/src/main.rs @@ -15,6 +15,7 @@ use log::*; use migrate::migrate; use reader::read as wicked_read; use serde::Serialize; +use simplelog::ConfigBuilder; use std::process::{ExitCode, Termination}; use tokio::sync::OnceCell; @@ -33,7 +34,7 @@ struct Cli { #[derive(Debug, Args)] struct GlobalOpts { - #[arg(long, global = true, default_value_t = LevelFilter::Warn, value_parser = clap::builder::PossibleValuesParser::new(["TRACE", "DEBUG", "INFO", "WARN", "ERROR"]).map(|s| s.parse::<LevelFilter>().unwrap()),)] + #[arg(long, global = true, default_value_t = LevelFilter::Info, value_parser = clap::builder::PossibleValuesParser::new(["TRACE", "DEBUG", "INFO", "WARN", "ERROR"]).map(|s| s.parse::<LevelFilter>().unwrap()),)] pub log_level: LevelFilter, #[arg(long, global = true, env = "MIGRATE_WICKED_WITHOUT_NETCONFIG")] @@ -141,7 +142,7 @@ async fn run_command(cli: Cli) -> anyhow::Result<()> { match migrate(paths).await { Ok(()) => Ok(()), - Err(e) => Err(anyhow::anyhow!("Migration failed: {:?}", e)), + Err(e) => Err(anyhow::anyhow!("Migration failed: {}", e)), } } } @@ -188,16 +189,21 @@ static MIGRATION_SETTINGS: OnceCell<MigrationSettings> = OnceCell::const_new(); async fn main() -> CliResult { let cli = Cli::parse(); + let config = ConfigBuilder::new() + .set_time_level(LevelFilter::Off) + .add_filter_allow("migrate_wicked".to_string()) + .build(); + simplelog::TermLogger::init( cli.global_opts.log_level, - simplelog::Config::default(), + config, simplelog::TerminalMode::Stderr, simplelog::ColorChoice::Auto, ) .unwrap(); if let Err(error) = run_command(cli).await { - eprintln!("{:?}", error); + log::error!("{}", error); return CliResult::Error; } diff --git a/rust/migrate-wicked/src/reader.rs b/rust/migrate-wicked/src/reader.rs index dcc75c9253..15b7f4f562 100644 --- a/rust/migrate-wicked/src/reader.rs +++ b/rust/migrate-wicked/src/reader.rs @@ -26,9 +26,20 @@ pub fn read_xml_file(path: PathBuf) -> Result<InterfacesResult, anyhow::Error> { let replaced_string = replace_colons(contents.as_str()); let deserializer = &mut quick_xml::de::Deserializer::from_str(replaced_string.as_str()); let mut unhandled_fields = vec![]; - let interfaces: Vec<Interface> = serde_ignored::deserialize(deserializer, |path| { + let interfaces: Vec<Interface> = match serde_ignored::deserialize(deserializer, |path| { unhandled_fields.push(path.to_string()); - })?; + }) { + Ok(interfaces) => interfaces, + Err(e) => { + let deserializer2 = + &mut quick_xml::de::Deserializer::from_str(replaced_string.as_str()); + let res: Result<Vec<Interface>, _> = serde_path_to_error::deserialize(deserializer2); + if let Err(path_error) = res { + log::error!("Error at {}: {}", path_error.path().to_string(), e); + } + return Err(e.into()); + } + }; let mut result = InterfacesResult { interfaces, netconfig: None,