aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/ZipArchive/ZipImporter.swift
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-12-06 19:05:46 +0530
committerRoopesh Chander <roop@roopc.net>2018-12-07 12:36:19 +0530
commitdcfa9473e955e372d2c32d7fc682a6fa9ff30bdf (patch)
treedfc481407b9b650076635fbe52e7f9f65dbcdd47 /WireGuard/WireGuard/ZipArchive/ZipImporter.swift
parentError handling: Introduce a WireGuardResult type to handle errors in callbacks across the app (diff)
downloadwireguard-apple-dcfa9473e955e372d2c32d7fc682a6fa9ff30bdf.tar.xz
wireguard-apple-dcfa9473e955e372d2c32d7fc682a6fa9ff30bdf.zip
Error handling: Use WireGuardAppError and WireGuardResult throughout the app
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/ZipArchive/ZipImporter.swift')
-rw-r--r--WireGuard/WireGuard/ZipArchive/ZipImporter.swift19
1 files changed, 14 insertions, 5 deletions
diff --git a/WireGuard/WireGuard/ZipArchive/ZipImporter.swift b/WireGuard/WireGuard/ZipArchive/ZipImporter.swift
index 4c439d46..507a823d 100644
--- a/WireGuard/WireGuard/ZipArchive/ZipImporter.swift
+++ b/WireGuard/WireGuard/ZipArchive/ZipImporter.swift
@@ -3,12 +3,19 @@
import UIKit
-enum ZipImporterError: Error {
+enum ZipImporterError: WireGuardAppError {
case noTunnelsInZipArchive
+
+ func alertText() -> (String, String) {
+ switch (self) {
+ case .noTunnelsInZipArchive:
+ return ("No tunnels in zip archive", "No .conf tunnel files were found inside the zip archive.")
+ }
+ }
}
class ZipImporter {
- static func importConfigFiles(from url: URL, completion: @escaping ([TunnelConfiguration?], Error?) -> Void) {
+ static func importConfigFiles(from url: URL, completion: @escaping (WireGuardResult<[TunnelConfiguration?]>) -> Void) {
DispatchQueue.global(qos: .userInitiated).async {
var unarchivedFiles: [(fileName: String, contents: Data)]
do {
@@ -26,9 +33,11 @@ class ZipImporter {
if (unarchivedFiles.isEmpty) {
throw ZipImporterError.noTunnelsInZipArchive
}
- } catch (let error) {
- DispatchQueue.main.async { completion([], error) }
+ } catch (let error as WireGuardAppError) {
+ DispatchQueue.main.async { completion(.failure(error)) }
return
+ } catch {
+ fatalError()
}
unarchivedFiles.sort { $0.fileName < $1.fileName }
@@ -45,7 +54,7 @@ class ZipImporter {
}
configs[i] = tunnelConfig
}
- DispatchQueue.main.async { completion(configs, nil) }
+ DispatchQueue.main.async { completion(.success(configs)) }
}
}
}