fix(vpn): handle non-file url on openvpn import

So openvpn import called to_file_path().unwrap(), which panics when the
file picker hands back a non-file:// url (sandboxed portal, etc). the
wireguard branch right above already handles this gracefully, so do the
same: return a Message::Error with a new OpenVpnConfigPath kind instead
of crashing.

Fixes #1896

- [x] I have disclosed use of any AI generated code in my commit
messages.
- If you are using an LLM, and do not fully understand the changes it is
making to the code base, do not create a PR.
- In our experience, AI generated code often results in overly complex
code that lacks enough context for a proper fix or feature inclusion.
This results in considerably longer code reviews. Due to this, AI
authored or partially authored PRs may be closed without comment.
- [x] I understand these changes in full and will be able to respond to
review comments.
- [x] My change is accurately described in the commit message.
- [x] My contribution is tested and working as described.
- [x] I have read the [Developer Certificate of
Origin](https://developercertificate.org/) and certify my contribution
under its conditions.

Signed-off-by: James A DellaMorte <dellamorte.james@comcast.net>
Co-authored-by: James A DellaMorte <dellamorte.james@comcast.net>
This commit is contained in:
JADella94 2026-06-16 16:22:02 -04:00 committed by GitHub
parent 9155a1e902
commit 1dd478aeb2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View file

@ -95,6 +95,7 @@ pub enum ErrorKind {
ConnectionEditor,
ConnectionSettings,
DbusConnection,
OpenVpnConfigPath,
UpdatingState,
WireGuardConfigPath,
WireGuardDevice,
@ -109,6 +110,7 @@ impl ErrorKind {
ErrorKind::ConnectionEditor => fl!("vpn-error", "connection-editor"),
ErrorKind::ConnectionSettings => fl!("vpn-error", "connection-settings"),
ErrorKind::DbusConnection => fl!("dbus-connection-error"),
ErrorKind::OpenVpnConfigPath => fl!("vpn-error", "openvpn-config-path"),
ErrorKind::UpdatingState => fl!("vpn-error", "updating-state"),
ErrorKind::WireGuardConfigPath => fl!("vpn-error", "wireguard-config-path"),
ErrorKind::WireGuardDevice => fl!("vpn-error", "wireguard-device"),
@ -1199,8 +1201,14 @@ fn add_network() -> Task<crate::app::Message> {
return Message::AddWireGuardDevice(device, filename.to_owned(), path);
} else {
super::nm_add_vpn_file("openvpn", response.url().to_file_path().unwrap())
.await
let Ok(path) = response.url().to_file_path() else {
return Message::Error(
ErrorKind::OpenVpnConfigPath,
fl!("vpn-error", "openvpn-config-path-desc"),
);
};
super::nm_add_vpn_file("openvpn", path).await
};
match result {

View file

@ -198,6 +198,8 @@ vpn-error = VPN Error
.connect = Failed to connect to VPN
.connection-editor = Connection editor failed
.connection-settings = Failed to get settings for active connections
.openvpn-config-path = Invalid file path for OpenVPN config
.openvpn-config-path-desc = Chosen file must be on a local file system.
.updating-state = Failed to update network manager state
.wireguard-config-path = Invalid file path for WireGuard config
.wireguard-config-path-desc = Chosen file must be on a local file system.