From: Jason A. Donenfeld Date: Fri, 28 Jun 2019 10:06:58 +0000 (+0200) Subject: UI: macOS: Show useful error message on .conf import X-Git-Tag: 0.0.20190610-13~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=26b7971ba6ccfcf243a9b3a6606e94a758d32375;p=thirdparty%2Fwireguard-apple.git UI: macOS: Show useful error message on .conf import Signed-off-by: Jason A. Donenfeld --- diff --git a/WireGuard/WireGuard/UI/TunnelImporter.swift b/WireGuard/WireGuard/UI/TunnelImporter.swift index cf05ff9..46f2c92 100644 --- a/WireGuard/WireGuard/UI/TunnelImporter.swift +++ b/WireGuard/WireGuard/UI/TunnelImporter.swift @@ -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()