From 2972b6c99d440b1316c00af45d65bed75f2f55f4 Mon Sep 17 00:00:00 2001 From: Ty Schenk Date: Thu, 28 Oct 2021 12:06:41 -0500 Subject: [PATCH 1/2] Fix throw compile error --- Sources/Segment/Utilities/JSON.swift | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Sources/Segment/Utilities/JSON.swift b/Sources/Segment/Utilities/JSON.swift index 006b4a9c..ae57643d 100644 --- a/Sources/Segment/Utilities/JSON.swift +++ b/Sources/Segment/Utilities/JSON.swift @@ -7,6 +7,18 @@ import Foundation +// MARK: - JSONError Definition +struct JSONError: Error { + let message: String + + init(_ message: String) { + self.message = message + } + + public var localizedDescription: String { + return message + } +} // MARK: - JSON Definition @@ -302,7 +314,7 @@ extension JSON { newArray.append(value) result = try JSON(newArray) default: - throw "This JSON object is not an array type." + throw JSONError("This JSON object is not an array type.") } return result } @@ -325,7 +337,7 @@ extension JSON { newObject[key] = value result = try JSON(newObject) default: - throw "This JSON object is not an array type." + throw JSONError("This JSON object is not an array type.") } return result } @@ -347,7 +359,7 @@ extension JSON { newObject.removeValue(forKey: key) result = try JSON(newObject) default: - throw "This JSON object is not an array type." + throw JSONError("This JSON object is not an array type.") } return result From a6ea35088031112e709c0d73fc56d3bcac2b66e7 Mon Sep 17 00:00:00 2001 From: Ty Schenk Date: Thu, 28 Oct 2021 12:40:30 -0500 Subject: [PATCH 2/2] fix error on compile --- Sources/Segment/Utilities/JSON.swift | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/Sources/Segment/Utilities/JSON.swift b/Sources/Segment/Utilities/JSON.swift index ae57643d..75430ef4 100644 --- a/Sources/Segment/Utilities/JSON.swift +++ b/Sources/Segment/Utilities/JSON.swift @@ -7,19 +7,6 @@ import Foundation -// MARK: - JSONError Definition -struct JSONError: Error { - let message: String - - init(_ message: String) { - self.message = message - } - - public var localizedDescription: String { - return message - } -} - // MARK: - JSON Definition public enum JSON: Equatable { @@ -32,6 +19,7 @@ public enum JSON: Equatable { private enum JSONError: Error { case unknown + case error(message: String) case nonJSONType(type: String) } @@ -314,7 +302,7 @@ extension JSON { newArray.append(value) result = try JSON(newArray) default: - throw JSONError("This JSON object is not an array type.") + throw JSONError.error(message: "This JSON object is not an array type.") } return result } @@ -337,7 +325,7 @@ extension JSON { newObject[key] = value result = try JSON(newObject) default: - throw JSONError("This JSON object is not an array type.") + throw JSONError.error(message: "This JSON object is not an array type.") } return result } @@ -359,7 +347,7 @@ extension JSON { newObject.removeValue(forKey: key) result = try JSON(newObject) default: - throw JSONError("This JSON object is not an array type.") + throw JSONError.error(message: "This JSON object is not an array type.") } return result