Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Error Message when wireguard-go not found. replacement for #232 #284

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions wireguard-control/src/backends/userspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,18 +274,29 @@ fn get_userspace_implementation() -> String {

fn start_userspace_wireguard(iface: &InterfaceName) -> io::Result<Output> {
let mut command = Command::new(get_userspace_implementation());
let output = if cfg!(target_os = "linux") {
command.args(&[iface.to_string()]).output()?

let output_res = if cfg!(target_os = "linux") {
command.args(&[iface.to_string()]).output()
} else {
command
.env("WG_TUN_NAME_FILE", &format!("{VAR_RUN_PATH}/{iface}.name"))
.args(["utun"])
.output()?
.output()
};
if !output.status.success() {
Err(io::ErrorKind::AddrNotAvailable.into())
} else {
Ok(output)

match output_res {
Ok(output) => {
if output.status.success() {
Ok(output)
} else {
Err(io::ErrorKind::AddrNotAvailable.into())
}
},
Err(e) if e.kind() == io::ErrorKind::NotFound => Err(io::Error::new(
io::ErrorKind::NotFound,
"Cannot find \"wireguard-go\". Specify a custom path with WG_USERSPACE_IMPLEMENTATION.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably pull get_userspace_implementation() into a local var called userspace_implementation and then use it in Command::new() above, as well as here:

Suggested change
"Cannot find \"wireguard-go\". Specify a custom path with WG_USERSPACE_IMPLEMENTATION.",
"Cannot find {userspace_implementation:?}. Specify a custom path with WG_USERSPACE_IMPLEMENTATION.",

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in the latest commit.

)),
Err(e) => Err(e),
}
}

Expand Down