From 305264d064b4d112ce3e6b7557ace83ff1d636db Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Tue, 11 Dec 2018 00:30:33 +0530 Subject: [PATCH] Error handling: alertText() can be nil Indicating that no alert is to be shown for that error. --- WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift | 2 +- WireGuard/WireGuard/VPN/TunnelsManager.swift | 2 +- WireGuard/WireGuard/WireGuardAppError.swift | 2 +- WireGuard/WireGuard/ZipArchive/ZipArchive.swift | 2 +- WireGuard/WireGuard/ZipArchive/ZipExporter.swift | 2 +- WireGuard/WireGuard/ZipArchive/ZipImporter.swift | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift b/WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift index 3c4a1bf..c613d67 100644 --- a/WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift +++ b/WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift @@ -8,7 +8,7 @@ class ErrorPresenter { static func showErrorAlert(error: WireGuardAppError, from sourceVC: UIViewController?, onDismissal: (() -> Void)? = nil, onPresented: (() -> Void)? = nil) { guard let sourceVC = sourceVC else { return } - let (title, message) = error.alertText() + guard let (title, message) = error.alertText() else { return } let okAction = UIAlertAction(title: "OK", style: .default) { (_) in onDismissal?() } diff --git a/WireGuard/WireGuard/VPN/TunnelsManager.swift b/WireGuard/WireGuard/VPN/TunnelsManager.swift index b36c9f8..9d04e1f 100644 --- a/WireGuard/WireGuard/VPN/TunnelsManager.swift +++ b/WireGuard/WireGuard/VPN/TunnelsManager.swift @@ -31,7 +31,7 @@ enum TunnelsManagerError: WireGuardAppError { case tunnelActivationFailedInternalError // startTunnel() succeeded, but activation failed case tunnelActivationFailedNoInternetConnection // startTunnel() succeeded, but activation failed since no internet - func alertText() -> (String, String) { + func alertText() -> (String, String)? { switch (self) { case .tunnelNameEmpty: return ("No name provided", "Can't create tunnel with an empty name") diff --git a/WireGuard/WireGuard/WireGuardAppError.swift b/WireGuard/WireGuard/WireGuardAppError.swift index 5289633..3e4707d 100644 --- a/WireGuard/WireGuard/WireGuardAppError.swift +++ b/WireGuard/WireGuard/WireGuardAppError.swift @@ -2,5 +2,5 @@ // Copyright © 2018 WireGuard LLC. All Rights Reserved. protocol WireGuardAppError: Error { - func alertText() -> (/* title */ String, /* message */ String) + func alertText() -> (/* title */ String, /* message */ String)? } diff --git a/WireGuard/WireGuard/ZipArchive/ZipArchive.swift b/WireGuard/WireGuard/ZipArchive/ZipArchive.swift index fe633d0..a849daa 100644 --- a/WireGuard/WireGuard/ZipArchive/ZipArchive.swift +++ b/WireGuard/WireGuard/ZipArchive/ZipArchive.swift @@ -8,7 +8,7 @@ enum ZipArchiveError: WireGuardAppError { case cantOpenOutputZipFileForWriting case badArchive - func alertText() -> (String, String) { + func alertText() -> (String, String)? { switch (self) { case .cantOpenInputZipFile: return ("Unable to read zip archive", "The zip archive could not be read.") diff --git a/WireGuard/WireGuard/ZipArchive/ZipExporter.swift b/WireGuard/WireGuard/ZipArchive/ZipExporter.swift index a4e9d7a..4f57613 100644 --- a/WireGuard/WireGuard/ZipArchive/ZipExporter.swift +++ b/WireGuard/WireGuard/ZipArchive/ZipExporter.swift @@ -6,7 +6,7 @@ import UIKit enum ZipExporterError: WireGuardAppError { case noTunnelsToExport - func alertText() -> (String, String) { + func alertText() -> (String, String)? { switch (self) { case .noTunnelsToExport: return ("Nothing to export", "There are no tunnels to export") diff --git a/WireGuard/WireGuard/ZipArchive/ZipImporter.swift b/WireGuard/WireGuard/ZipArchive/ZipImporter.swift index 507a823..d281fb6 100644 --- a/WireGuard/WireGuard/ZipArchive/ZipImporter.swift +++ b/WireGuard/WireGuard/ZipArchive/ZipImporter.swift @@ -6,7 +6,7 @@ import UIKit enum ZipImporterError: WireGuardAppError { case noTunnelsInZipArchive - func alertText() -> (String, String) { + func alertText() -> (String, String)? { switch (self) { case .noTunnelsInZipArchive: return ("No tunnels in zip archive", "No .conf tunnel files were found inside the zip archive.")