fix(browser): surface actual camoufox-bridge error on daemon start failure
trigger_daemon_start now captures stdout/stderr and exit code instead of silently redirecting to a log file. On failure it prints the actual error, making it obvious what went wrong (npm install issue, node version mismatch, etc.).
This commit is contained in:
@@ -18,7 +18,6 @@
|
|||||||
//! `/home/user/.nvm/versions/node/v22/bin/npx`)
|
//! `/home/user/.nvm/versions/node/v22/bin/npx`)
|
||||||
//! 2. `"npx"` on Linux/macOS, `"npx.cmd"` on Windows — PATH lookup
|
//! 2. `"npx"` on Linux/macOS, `"npx.cmd"` on Windows — PATH lookup
|
||||||
|
|
||||||
use std::process::Stdio;
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use tokio::process::Command;
|
use tokio::process::Command;
|
||||||
@@ -136,24 +135,55 @@ async fn trigger_daemon_start(session: &str, node_path: Option<&str>) -> Result<
|
|||||||
.map_err(|e| format!("Cannot create {}: {}", log_dir.display(), e))?;
|
.map_err(|e| format!("Cannot create {}: {}", log_dir.display(), e))?;
|
||||||
let log_file = log_dir.join("camoufox-daemon-spawn.log");
|
let log_file = log_dir.join("camoufox-daemon-spawn.log");
|
||||||
|
|
||||||
let log = std::fs::File::create(&log_file)
|
|
||||||
.map_err(|e| format!("Cannot create log file: {}", e))?;
|
|
||||||
|
|
||||||
let npx = resolve_npx(node_path);
|
let npx = resolve_npx(node_path);
|
||||||
|
|
||||||
// Run a command — the CLI auto-starts the daemon as a side effect
|
// Run a command — the CLI auto-starts the daemon as a side effect
|
||||||
let _output = Command::new(npx)
|
let output = Command::new(npx)
|
||||||
.args(&[
|
.args(&[
|
||||||
"camoufox-browser@latest",
|
"camoufox-browser@latest",
|
||||||
"tab_list",
|
"tab_list",
|
||||||
"--session", session,
|
"--session", session,
|
||||||
])
|
])
|
||||||
.stdout(Stdio::from(log.try_clone().map_err(|e| e.to_string())?))
|
|
||||||
.stderr(Stdio::from(log))
|
|
||||||
.output()
|
.output()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| format!("{} failed: {}. Is Node.js installed?", npx, e))?;
|
.map_err(|e| {
|
||||||
|
let hint = if node_path.is_none() {
|
||||||
|
"\n → Set [browser].node_path in your config, e.g.:\n [browser]\n node_path = \"/Users/yourname/.nvm/versions/node/v22/bin/npx\"".to_string()
|
||||||
|
} else {
|
||||||
|
format!("\n → npx at '{}' not found or not executable", npx)
|
||||||
|
};
|
||||||
|
format!("{} failed: {}. Is Node.js installed?{}", npx, e, hint)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
if !output.status.success() {
|
||||||
|
// Read the log for details
|
||||||
|
let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();
|
||||||
|
let stdout = String::from_utf8_lossy(&output.stdout).trim().to_string();
|
||||||
|
let details = if !stderr.is_empty() { stderr.clone() } else { stdout.clone() };
|
||||||
|
|
||||||
|
// Also save to log file for reference
|
||||||
|
let _ = std::fs::write(&log_file, format!(
|
||||||
|
"exit_code: {}\nstdout:\n{}\nstderr:\n{}\n",
|
||||||
|
output.status.code().unwrap_or(-1),
|
||||||
|
stdout, stderr
|
||||||
|
));
|
||||||
|
|
||||||
|
let hint = if node_path.is_none() {
|
||||||
|
"\n → Try setting [browser].node_path in your config:\n [browser]\n node_path = \"/Users/yourname/.nvm/versions/node/v22/bin/npx\"".to_string()
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
};
|
||||||
|
|
||||||
|
return Err(format!(
|
||||||
|
"camoufox-browser failed (exit: {}):\n {}\n → Full log saved to {}{}",
|
||||||
|
output.status.code().unwrap_or(-1),
|
||||||
|
details,
|
||||||
|
log_file.display(),
|
||||||
|
hint,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Command succeeded — daemon should be starting
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user