]> git.ipfire.org Git - thirdparty/wireguard-apple.git/commitdiff
UI: macOS: Show useful error message on .conf import
authorJason A. Donenfeld <Jason@zx2c4.com>
Fri, 28 Jun 2019 10:06:58 +0000 (12:06 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Fri, 28 Jun 2019 10:07:18 +0000 (12:07 +0200)
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
WireGuard/WireGuard/UI/TunnelImporter.swift

index cf05ff92d538a5161cbeb989efcfff1f5b36c2bd..46f2c92675439082a488ae8de1ce3e42588925e6 100644 (file)
@@ -44,10 +44,20 @@ class TunnelImporter {
                         }
                         return
                     }
-                    let tunnelConfiguration = try? TunnelConfiguration(fromWgQuickConfig: fileContents, called: fileBaseName)
+                    var parseError: Error?
+                    var tunnelConfiguration: TunnelConfiguration?
+                    do {
+                        tunnelConfiguration = try TunnelConfiguration(fromWgQuickConfig: fileContents, called: fileBaseName)
+                    } catch let error {
+                        parseError = error
+                    }
                     DispatchQueue.main.async {
-                        if tunnelConfiguration == nil {
-                            lastFileImportErrorText = (title: tr("alertBadConfigImportTitle"), message: tr(format: "alertBadConfigImportMessage (%@)", fileName))
+                        if parseError != nil {
+                            if let parseError = parseError as? WireGuardAppError {
+                                lastFileImportErrorText = parseError.alertText
+                            } else {
+                                lastFileImportErrorText = (title: tr("alertBadConfigImportTitle"), message: tr(format: "alertBadConfigImportMessage (%@)", fileName))
+                            }
                         }
                         configs.append(tunnelConfiguration)
                         dispatchGroup.leave()