diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2022-02-17 13:18:34 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2022-02-22 11:24:14 +0100 |
| commit | dcb8a8a29734dce970025c122c3402640fd215ae (patch) | |
| tree | 62a3d6630bc24bee9fcac9fac52c8cc31592651e | |
| parent | 2923b851ec06c9823171559c3f4334bcca22f6ae (diff) | |
| download | mullvadvpn-dcb8a8a29734dce970025c122c3402640fd215ae.tar.xz mullvadvpn-dcb8a8a29734dce970025c122c3402640fd215ae.zip | |
Implement custom error messages for Coding errors
| -rw-r--r-- | ios/MullvadVPN.xcodeproj/project.pbxproj | 6 | ||||
| -rw-r--r-- | ios/MullvadVPN/CodingErrors+ChainedError.swift | 53 |
2 files changed, 59 insertions, 0 deletions
diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj index 06b01ec444..15a2b8d6f3 100644 --- a/ios/MullvadVPN.xcodeproj/project.pbxproj +++ b/ios/MullvadVPN.xcodeproj/project.pbxproj @@ -79,6 +79,8 @@ 58293FB125124117005D0BB5 /* CustomTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58293FB025124117005D0BB5 /* CustomTextField.swift */; }; 58293FB3251241B4005D0BB5 /* CustomTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58293FB2251241B3005D0BB5 /* CustomTextView.swift */; }; 58293FB725138B88005D0BB5 /* CustomNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58293FB625138B88005D0BB5 /* CustomNavigationController.swift */; }; + 582AD44027BE616E002A6BFC /* CodingErrors+ChainedError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 582AD43F27BE616E002A6BFC /* CodingErrors+ChainedError.swift */; }; + 582AD44127BE6178002A6BFC /* CodingErrors+ChainedError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 582AD43F27BE616E002A6BFC /* CodingErrors+ChainedError.swift */; }; 582AE3102440A6CA00E6733A /* AccountTokenInput.swift in Sources */ = {isa = PBXBuildFile; fileRef = 582AE30F2440A6CA00E6733A /* AccountTokenInput.swift */; }; 582AE3122440CA0D00E6733A /* AccountTokenInputTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 582AE3112440CA0D00E6733A /* AccountTokenInputTests.swift */; }; 582AE3132440CA2700E6733A /* AccountTokenInput.swift in Sources */ = {isa = PBXBuildFile; fileRef = 582AE30F2440A6CA00E6733A /* AccountTokenInput.swift */; }; @@ -412,6 +414,7 @@ 58293FB025124117005D0BB5 /* CustomTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomTextField.swift; sourceTree = "<group>"; }; 58293FB2251241B3005D0BB5 /* CustomTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomTextView.swift; sourceTree = "<group>"; }; 58293FB625138B88005D0BB5 /* CustomNavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomNavigationController.swift; sourceTree = "<group>"; }; + 582AD43F27BE616E002A6BFC /* CodingErrors+ChainedError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CodingErrors+ChainedError.swift"; sourceTree = "<group>"; }; 582AE30F2440A6CA00E6733A /* AccountTokenInput.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountTokenInput.swift; sourceTree = "<group>"; }; 582AE3112440CA0D00E6733A /* AccountTokenInputTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountTokenInputTests.swift; sourceTree = "<group>"; }; 582BB1AE229566420055B6EF /* SettingsCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsCell.swift; sourceTree = "<group>"; }; @@ -890,6 +893,7 @@ 5891BF1B25E3E3EB006D6FB0 /* Bundle+ProductVersion.swift */, 58F840B12464491D0044E708 /* ChainedError.swift */, 587EB669270EFACB00123C75 /* CharacterSet+IPAddress.swift */, + 582AD43F27BE616E002A6BFC /* CodingErrors+ChainedError.swift */, 58A1AA8B23F5584B009F7EA6 /* ConnectionPanelView.swift */, 58B43C1825F77DB60002C8C3 /* ConnectMainContentView.swift */, 58CCA00F224249A1004F3011 /* ConnectViewController.swift */, @@ -1367,6 +1371,7 @@ 58095C512760BBB500890776 /* AddressCacheTracker.swift in Sources */, 584D26C6270C8741004EA533 /* SettingsDNSTextCell.swift in Sources */, 585DA87D26B0254000B8C587 /* RelayCacheIO.swift in Sources */, + 582AD44027BE616E002A6BFC /* CodingErrors+ChainedError.swift in Sources */, 58F2E148276A307400A79513 /* MapConnectionStatusOperation.swift in Sources */, 58BA693123EADA6A009DC256 /* SimulatorTunnelProvider.swift in Sources */, 587C575326D2615F005EF767 /* PacketTunnelOptions.swift in Sources */, @@ -1567,6 +1572,7 @@ 587AD7C723421D8600E93A53 /* TunnelSettings.swift in Sources */, 5875960B26F3723000BF6711 /* TunnelIPC.swift in Sources */, 58AEEF662344A37400C9BBD5 /* KeychainError.swift in Sources */, + 582AD44127BE6178002A6BFC /* CodingErrors+ChainedError.swift in Sources */, 5840250222B1124600E4CFEC /* IPAddress+Codable.swift in Sources */, 5820675C26E6576800655B05 /* RelayCache.swift in Sources */, 58FAEDF1245069CA00CB0F5B /* KeychainAttributes.swift in Sources */, diff --git a/ios/MullvadVPN/CodingErrors+ChainedError.swift b/ios/MullvadVPN/CodingErrors+ChainedError.swift new file mode 100644 index 0000000000..e14d61473b --- /dev/null +++ b/ios/MullvadVPN/CodingErrors+ChainedError.swift @@ -0,0 +1,53 @@ +// +// CodingErrors+ChainedError.swift +// MullvadVPN +// +// Created by pronebird on 17/02/2022. +// Copyright © 2022 Mullvad VPN AB. All rights reserved. +// + +import Foundation + +extension DecodingError: CustomChainedErrorDescriptionProtocol { + var customErrorDescription: String? { + switch self { + case .typeMismatch(let type, let context): + return "Type mismatch, expected \(type) for key at \"\(context.codingPath.codingPathString)\"." + + case .valueNotFound(_, let context): + return "Value not found at \"\(context.codingPath.codingPathString)\"." + + case .keyNotFound(let codingKey, let context): + return "Key \"\(codingKey.stringValue)\" not found at \"\(context.codingPath.codingPathString)\"." + + case .dataCorrupted: + return "Data corrupted." + + @unknown default: + return nil + } + } +} + +extension EncodingError: CustomChainedErrorDescriptionProtocol { + var customErrorDescription: String? { + switch self { + case .invalidValue(_, let context): + return "Invalid value at \"\(context.codingPath.codingPathString)\"" + + @unknown default: + return nil + } + } +} + +private extension Array where Element == CodingKey { + var codingPathString: String { + if isEmpty { + return "<root>" + } else { + return map { $0.stringValue } + .joined(separator: ".") + } + } +} |
