Skip to content

Commit

Permalink
Merge pull request #124 from xero-lib/master
Browse files Browse the repository at this point in the history
Implemented proper error handling for socket removal
  • Loading branch information
Toqozz authored Jan 13, 2024
2 parents e47b05f + 38b0e45 commit 1796bbf
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ impl CLIListener {
println!(
"A wired socket exists; taking ownership. Existing wired processes will not receive CLI calls."
);
std::fs::remove_file(SOCKET_PATH).unwrap();

if std::fs::remove_file(SOCKET_PATH).is_err_and(|e| e.kind() == ErrorKind::PermissionDenied) {
return Err(CLIError::Socket(io::Error::new(
ErrorKind::PermissionDenied,
"Could not remove existing wired socket. Please stop all wired instances, remove /tmp/wired.sock and try again.",
)));
}
}

let listener = UnixListener::bind(socket_path).map_err(CLIError::Socket)?;
Expand Down

0 comments on commit 1796bbf

Please sign in to comment.