From 9ff28fc9cdcbd95821d3410b05969b5bf1cd12fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Sommer?= Date: Mon, 1 Apr 2024 22:26:51 -0500 Subject: [PATCH] Improve config errors Co-authored-by: Ottatop <120758733+Ottatop@users.noreply.github.com> --- src/config.rs | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/config.rs b/src/config.rs index c92b355..2671ce1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -220,12 +220,18 @@ pub struct ConnectorSavedState { /// Parse a metaconfig file in `config_dir`, if any. fn parse_metaconfig(config_dir: &Path) -> anyhow::Result { - let config_dir = config_dir.join("metaconfig.toml"); + let metaconfig_path = config_dir.join("metaconfig.toml"); - let metaconfig = - std::fs::read_to_string(config_dir).context("Failed to read metaconfig.toml")?; - - toml::from_str(&metaconfig).context("Failed to deserialize toml") + std::fs::read_to_string(&metaconfig_path) + .with_context(|| format!("Failed to read {}", metaconfig_path.display())) + .and_then(|data| { + toml::from_str(&data).with_context(|| { + format!( + "Failed to deserialize toml in {}", + metaconfig_path.display() + ) + }) + }) } /// Get the config dir. This is $PINNACLE_CONFIG_DIR, then $XDG_CONFIG_HOME/pinnacle, @@ -276,7 +282,7 @@ impl State { ); anyhow::bail!("default lua config dir does not work"); } - return load_default_config(self, &err.to_string()); + return load_default_config(self, &format!("{}, {}", err, err.root_cause())); } }; @@ -370,19 +376,28 @@ impl State { debug!("Config envs are {envs:?}"); - info!("Starting config at {}", config_dir.display()); + info!( + "Starting config process at {} with {:?}", + config_dir.display(), + metaconfig.command + ); - let mut child = match tokio::process::Command::new(arg0) - .args(command) + let mut cmd = tokio::process::Command::new(arg0); + cmd.args(command) .envs(envs) .current_dir(config_dir) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) - .kill_on_drop(true) - .spawn() - { + .kill_on_drop(true); + + let mut child = match cmd.spawn() { Ok(child) => child, - Err(err) => return load_default_config(self, &err.to_string()), + Err(err) => { + return load_default_config( + self, + &format!("failed to start config process {cmd:?}: {err}"), + ) + } }; info!("Started config with {:?}", metaconfig.command);