Skip to content

Commit 90426aa

Browse files
committed
Improve elevated start error reporting
1 parent b57b7e0 commit 90426aa

2 files changed

Lines changed: 27 additions & 20 deletions

File tree

src/gui.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,15 @@ fn execute_action(config_path: &Path, action: GuiAction) -> Result<String> {
825825
config_path.to_string_lossy().into_owned(),
826826
subcommand.to_string(),
827827
];
828-
run_elevated(&cli_binary, &args).with_context(|| "elevation or command execution failed")?;
828+
if let Err(error) = run_elevated(&cli_binary, &args) {
829+
if let Ok(status) = service::status(Some(config_path.to_path_buf()))
830+
&& let Some(last_error) = status.last_error
831+
{
832+
return Err(Error::msg(last_error))
833+
.with_context(|| "elevation or command execution failed");
834+
}
835+
return Err(error).with_context(|| "elevation or command execution failed");
836+
}
829837

830838
let deadline = Instant::now() + Duration::from_secs(12);
831839
loop {

src/service.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,24 +78,24 @@ pub async fn run_foreground(config_path: Option<PathBuf>, with_setup: bool) -> R
7878

7979
pub fn helper_start(config_path: Option<PathBuf>) -> Result<()> {
8080
let paths = resolve_paths(config_path)?;
81-
let config = AppConfig::load_or_create(&paths.config_path)?;
82-
ensure_elevated(&config, true)?;
81+
let start_result = (|| -> Result<()> {
82+
let config = AppConfig::load_or_create(&paths.config_path)?;
83+
ensure_elevated(&config, true)?;
8384

84-
let current = state::refresh(&paths)?;
85-
if current.running {
86-
return Ok(());
87-
}
85+
let current = state::refresh(&paths)?;
86+
if current.running {
87+
return Ok(());
88+
}
8889

89-
let bundle = ensure_bundle(&config, &paths.cert_dir)?;
90-
#[cfg(not(target_os = "macos"))]
91-
install_ca(&bundle.ca_cert_path, &config.ca_common_name)?;
92-
#[cfg(target_os = "macos")]
93-
let _ = bundle;
94-
apply_hosts(&config)?;
95-
state::mark_starting(&paths)?;
90+
let bundle = ensure_bundle(&config, &paths.cert_dir)?;
91+
#[cfg(not(target_os = "macos"))]
92+
install_ca(&bundle.ca_cert_path, &config.ca_common_name)?;
93+
#[cfg(target_os = "macos")]
94+
let _ = bundle;
95+
apply_hosts(&config)?;
96+
state::mark_starting(&paths)?;
9697

97-
let cli_binary = current_cli_binary()?;
98-
let start_result = (|| -> Result<()> {
98+
let cli_binary = current_cli_binary()?;
9999
let args = vec![
100100
"--config".to_string(),
101101
paths.config_path.to_string_lossy().into_owned(),
@@ -116,14 +116,13 @@ pub fn helper_start(config_path: Option<PathBuf>) -> Result<()> {
116116
Ok(())
117117
})();
118118

119-
if let Err(error) = start_result {
119+
if let Err(error) = &start_result {
120120
let _ = remove_hosts();
121121
let _ = state::clear_pid(&paths);
122-
let _ = state::mark_error(&paths, &error.to_string());
123-
return Err(error);
122+
let _ = state::mark_error(&paths, &format!("{error:#}"));
124123
}
125124

126-
Ok(())
125+
start_result
127126
}
128127

129128
pub fn helper_stop(config_path: Option<PathBuf>) -> Result<()> {

0 commit comments

Comments
 (0)