1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-24 13:32:50 -05:00

vpn: aggregate all import errors

- we are dumb about importing by just trying to import everythting
- that caused errors to not be represented correctly
- just aggregate them all and present them in toast details
- Better would be to detect the type of file being imported, but this is
  better than nothing
This commit is contained in:
bbedward
2026-01-07 13:22:56 -05:00
parent a205df1bd6
commit ec2b3d0d4b
2 changed files with 10 additions and 10 deletions

View File

@@ -3,6 +3,7 @@ package network
import ( import (
"bufio" "bufio"
"context" "context"
"errors"
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
@@ -925,25 +926,24 @@ func (b *NetworkManagerBackend) ImportVPN(filePath string, name string) (*VPNImp
func (b *NetworkManagerBackend) importVPNWithNmcli(filePath string, name string) (*VPNImportResult, error) { func (b *NetworkManagerBackend) importVPNWithNmcli(filePath string, name string) (*VPNImportResult, error) {
vpnTypes := []string{"openvpn", "wireguard", "vpnc", "pptp", "l2tp", "openconnect", "strongswan"} vpnTypes := []string{"openvpn", "wireguard", "vpnc", "pptp", "l2tp", "openconnect", "strongswan"}
var output []byte var allErrors []error
var err error var outputStr string
for _, vpnType := range vpnTypes { for _, vpnType := range vpnTypes {
args := []string{"connection", "import", "type", vpnType, "file", filePath} cmd := exec.Command("nmcli", "connection", "import", "type", vpnType, "file", filePath)
cmd := exec.Command("nmcli", args...) output, err := cmd.CombinedOutput()
output, err = cmd.CombinedOutput()
if err == nil { if err == nil {
outputStr = string(output)
break break
} }
allErrors = append(allErrors, fmt.Errorf("%s: %s", vpnType, strings.TrimSpace(string(output))))
} }
if err != nil { if len(allErrors) == len(vpnTypes) {
return &VPNImportResult{ return &VPNImportResult{
Success: false, Success: false,
Error: fmt.Sprintf("import failed: %s", strings.TrimSpace(string(output))), Error: errors.Join(allErrors...).Error(),
}, nil }, nil
} }
outputStr := string(output)
var connUUID, connName string var connUUID, connName string
lines := strings.Split(outputStr, "\n") lines := strings.Split(outputStr, "\n")

View File

@@ -95,7 +95,7 @@ Singleton {
} }
importError = response.result.error || "Import failed"; importError = response.result.error || "Import failed";
ToastService.showError(importError); ToastService.showError(I18n.tr("Failed to import VPN"), importError);
}); });
} }