fix: improve daemon startup error handling and diagnostics (#337)
* fixes * add debugging
This commit is contained in:
+35
-1
@@ -239,6 +239,37 @@ pub fn ensure_daemon(
|
|||||||
.map_err(|e| format!("Failed to create socket directory: {}", e))?;
|
.map_err(|e| format!("Failed to create socket directory: {}", e))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pre-flight check: Validate socket path length (Unix limit is 104 bytes including null terminator)
|
||||||
|
#[cfg(unix)]
|
||||||
|
{
|
||||||
|
let socket_path = get_socket_path(session);
|
||||||
|
let path_len = socket_path.as_os_str().len();
|
||||||
|
if path_len > 103 {
|
||||||
|
return Err(format!(
|
||||||
|
"Session name '{}' is too long. Socket path would be {} bytes (max 103).\n\
|
||||||
|
Use a shorter session name or set AGENT_BROWSER_SOCKET_DIR to a shorter path.",
|
||||||
|
session, path_len
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pre-flight check: Verify socket directory is writable
|
||||||
|
{
|
||||||
|
let test_file = socket_dir.join(".write_test");
|
||||||
|
match fs::write(&test_file, b"") {
|
||||||
|
Ok(_) => {
|
||||||
|
let _ = fs::remove_file(&test_file);
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
return Err(format!(
|
||||||
|
"Socket directory '{}' is not writable: {}",
|
||||||
|
socket_dir.display(),
|
||||||
|
e
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let exe_path = env::current_exe().map_err(|e| e.to_string())?;
|
let exe_path = env::current_exe().map_err(|e| e.to_string())?;
|
||||||
// Canonicalize to resolve symlinks (e.g., npm global bin symlink -> actual binary)
|
// Canonicalize to resolve symlinks (e.g., npm global bin symlink -> actual binary)
|
||||||
let exe_path = exe_path.canonicalize().unwrap_or(exe_path);
|
let exe_path = exe_path.canonicalize().unwrap_or(exe_path);
|
||||||
@@ -400,7 +431,10 @@ pub fn ensure_daemon(
|
|||||||
thread::sleep(Duration::from_millis(100));
|
thread::sleep(Duration::from_millis(100));
|
||||||
}
|
}
|
||||||
|
|
||||||
Err("Daemon failed to start".to_string())
|
Err(format!(
|
||||||
|
"Daemon failed to start (socket: {})",
|
||||||
|
get_socket_dir().join(format!("{}.sock", session)).display()
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn connect(session: &str) -> Result<Connection, String> {
|
fn connect(session: &str) -> Result<Connection, String> {
|
||||||
|
|||||||
+23
-3
@@ -443,14 +443,34 @@ fn main() {
|
|||||||
launch_cmd["ignoreHTTPSErrors"] = json!(true);
|
launch_cmd["ignoreHTTPSErrors"] = json!(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = send_command(launch_cmd, &flags.session) {
|
match send_command(launch_cmd, &flags.session) {
|
||||||
if !flags.json {
|
Ok(resp) if !resp.success => {
|
||||||
|
// Launch command failed (e.g., invalid state file, profile error)
|
||||||
|
let error_msg = resp
|
||||||
|
.error
|
||||||
|
.unwrap_or_else(|| "Browser launch failed".to_string());
|
||||||
|
if flags.json {
|
||||||
|
println!(r#"{{"success":false,"error":"{}"}}"#, error_msg);
|
||||||
|
} else {
|
||||||
|
eprintln!("{} {}", color::error_indicator(), error_msg);
|
||||||
|
}
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
if flags.json {
|
||||||
|
println!(r#"{{"success":false,"error":"{}"}}"#, e);
|
||||||
|
} else {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"{} Could not configure browser: {}",
|
"{} Could not configure browser: {}",
|
||||||
color::warning_indicator(),
|
color::error_indicator(),
|
||||||
e
|
e
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
Ok(_) => {
|
||||||
|
// Launch succeeded
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1107,8 +1107,12 @@ export class BrowserManager {
|
|||||||
context = await launcher.launchPersistentContext(profilePath, {
|
context = await launcher.launchPersistentContext(profilePath, {
|
||||||
headless: options.headless ?? true,
|
headless: options.headless ?? true,
|
||||||
executablePath: options.executablePath,
|
executablePath: options.executablePath,
|
||||||
|
args: options.args,
|
||||||
viewport,
|
viewport,
|
||||||
extraHTTPHeaders: options.headers,
|
extraHTTPHeaders: options.headers,
|
||||||
|
userAgent: options.userAgent,
|
||||||
|
...(options.proxy && { proxy: options.proxy }),
|
||||||
|
ignoreHTTPSErrors: options.ignoreHTTPSErrors ?? false,
|
||||||
});
|
});
|
||||||
this.isPersistentContext = true;
|
this.isPersistentContext = true;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user