JonathanxD / openaws-vpn-client

Unofficial open-source AWS VPN Client GUI for Linux
Other
62 stars 14 forks source link

Log to help understand you are missing share/pwd.txt #6

Closed pkubowicz closed 1 year ago

pkubowicz commented 1 year ago

Previously, not having this file produced just an error from openvpn. It wasn't clear if this file was missing due to something broken during SAML auth or for another reason.

[83582] 2023-07-03 17:54:28 WARNING: cannot stat file './pwd.txt': No such file or directory (errno=2)
[83582] Options error: --auth-user-pass fails with './pwd.txt': No such file or directory (errno=2)
[83582] Options error: Please correct these errors.

Also nothing user-friendly when executed with RUST_BACKTRACE=1:

thread 'tokio-runtime-worker' panicked at 'called `Option::unwrap()` on a `None` value', src/cmd.rs:103:19
stack backtrace:
   0: rust_begin_unwind
             at /rustc/532d2b14c05f9bc20b2d27cbb5f4550d28343a36/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/532d2b14c05f9bc20b2d27cbb5f4550d28343a36/library/core/src/panicking.rs:107:14
   2: core::panicking::panic
             at /rustc/532d2b14c05f9bc20b2d27cbb5f4550d28343a36/library/core/src/panicking.rs:48:5
   3: core::option::Option<T>::unwrap
             at /rustc/532d2b14c05f9bc20b2d27cbb5f4550d28343a36/library/core/src/option.rs:747:21
   4: openaws_vpn_client::cmd::run_ovpn::{{closure}}
             at ./src/cmd.rs:103:14

The reason was that I accidentally removed share/ while trying to fix openvpn compilation. Looking at sources confused me even more, because pwd.txt is used twice in 2 different directories (in share and in a temp directory). I was assuming SAML failed. But it was me failing to do git reset --hard.

After rethinking, I am convinced more people will run into same problem, even without removing anything from sources. It's because the current code uses relative paths, so if you start the binary from any directory other than main repository directory, share/pwd.txt won't be found and you will get the cryptic error.

I started learning Rust 2 hours ago in order to create this PR, so forgive me if I miss some Rust idioms. I tried to keep the code changes minimal but still useful.

JonathanxD commented 1 year ago

I started learning Rust 2 hours ago in order to create this PR, so forgive me if I miss some Rust idioms. I tried to keep the code changes minimal but still useful.

Don't worry, this code base is extremely messy. As long as it compiles and is not something absurd, I'm fine with it.

Thanks for the contribution.