diff --git a/Source/AwsCommonRuntimeKit/crt/Utilities.swift b/Source/AwsCommonRuntimeKit/crt/Utilities.swift index 796f3bd7..52624848 100644 --- a/Source/AwsCommonRuntimeKit/crt/Utilities.swift +++ b/Source/AwsCommonRuntimeKit/crt/Utilities.swift @@ -148,7 +148,7 @@ extension TimeInterval { let _millisecond = (self * 1_000).rounded() guard _millisecond >= 0 && _millisecond <= Double(UInt32.max) else { // todo convert the millisecond conversion errors into aws-crt-swift errors - throw CommonRunTimeError.crtError(CRTError(code: AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue)) + throw CommonRunTimeError.crtError(CRTError(code: AWS_ERROR_INVALID_ARGUMENT.rawValue)) } return UInt32(_millisecond) } @@ -157,7 +157,7 @@ extension TimeInterval { let _millisecond = (self * 1_000).rounded() guard _millisecond >= 0 && _millisecond <= Double(UInt64.max) else { // todo convert the millisecond conversion errors into aws-crt-swift errors - throw CommonRunTimeError.crtError(CRTError(code: AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue)) + throw CommonRunTimeError.crtError(CRTError(code: AWS_ERROR_INVALID_ARGUMENT.rawValue)) } return UInt64(_millisecond) } @@ -165,7 +165,7 @@ extension TimeInterval { func secondUInt16() throws -> UInt16 { guard self >= 0 && self <= Double(UInt16.max) else { // todo convert the millisecond conversion errors into aws-crt-swift errors - throw CommonRunTimeError.crtError( CRTError(code: AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue)) + throw CommonRunTimeError.crtError( CRTError(code: AWS_ERROR_INVALID_ARGUMENT.rawValue)) } return UInt16(self) } @@ -173,7 +173,7 @@ extension TimeInterval { func secondUInt32() throws -> UInt32 { guard self >= 0 && self <= Double(UInt32.max) else { // todo convert the millisecond conversion errors into aws-crt-swift errors - throw CommonRunTimeError.crtError( CRTError(code: AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue)) + throw CommonRunTimeError.crtError( CRTError(code: AWS_ERROR_INVALID_ARGUMENT.rawValue)) } return UInt32(self) } diff --git a/Source/AwsCommonRuntimeKit/mqtt/Mqtt5Client.swift b/Source/AwsCommonRuntimeKit/mqtt/Mqtt5Client.swift index b16a1810..6ca86782 100644 --- a/Source/AwsCommonRuntimeKit/mqtt/Mqtt5Client.swift +++ b/Source/AwsCommonRuntimeKit/mqtt/Mqtt5Client.swift @@ -366,7 +366,7 @@ public class Mqtt5ClientCore { guard let rawValue = self.rawValue else { continuationCore.release() return continuation.resume(throwing: CommonRunTimeError.crtError( - CRTError(code: AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue, context: "Mqtt client is closed."))) + CRTError(code: AWS_ERROR_INVALID_ARGUMENT.rawValue, context: "Mqtt client is closed."))) } let result = aws_mqtt5_client_publish(rawValue, publishPacketPointer, &callbackOptions) @@ -401,7 +401,7 @@ public class Mqtt5ClientCore { guard let rawValue = self.rawValue else { continuationCore.release() return continuation.resume(throwing: CommonRunTimeError.crtError( - CRTError(code: AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue, context: "Mqtt client is closed."))) + CRTError(code: AWS_ERROR_INVALID_ARGUMENT.rawValue, context: "Mqtt client is closed."))) } let result = aws_mqtt5_client_unsubscribe(rawValue, unsubscribePacketPointer, &callbackOptions) guard result == AWS_OP_SUCCESS else { diff --git a/Source/AwsCommonRuntimeKit/mqtt/Mqtt5Options.swift b/Source/AwsCommonRuntimeKit/mqtt/Mqtt5Options.swift index 0e182790..410f7086 100644 --- a/Source/AwsCommonRuntimeKit/mqtt/Mqtt5Options.swift +++ b/Source/AwsCommonRuntimeKit/mqtt/Mqtt5Options.swift @@ -111,7 +111,7 @@ public class MqttConnectOptions: CStruct { func validateConversionToNative() throws { if let keepAliveInterval { if keepAliveInterval < 0 || keepAliveInterval > Double(UInt16.max) { - throw CommonRunTimeError.crtError(CRTError(code: AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue, + throw CommonRunTimeError.crtError(CRTError(code: AWS_ERROR_INVALID_ARGUMENT.rawValue, context: "Invalid keepAliveInterval value")) } } @@ -119,14 +119,14 @@ public class MqttConnectOptions: CStruct { do { _ = try sessionExpiryInterval?.secondUInt32() } catch { - throw CommonRunTimeError.crtError(CRTError(code: AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue, + throw CommonRunTimeError.crtError(CRTError(code: AWS_ERROR_INVALID_ARGUMENT.rawValue, context: "Invalid sessionExpiryInterval value")) } do { _ = try willDelayInterval?.secondUInt32() } catch { - throw CommonRunTimeError.crtError(CRTError(code: AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue, + throw CommonRunTimeError.crtError(CRTError(code: AWS_ERROR_INVALID_ARGUMENT.rawValue, context: "Invalid willDelayInterval value")) } } @@ -343,41 +343,41 @@ public class MqttClientOptions: CStructWithUserData { do { _ = try minReconnectDelay?.millisecondUInt64() } catch { - throw CommonRunTimeError.crtError(CRTError(code: AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue, + throw CommonRunTimeError.crtError(CRTError(code: AWS_ERROR_INVALID_ARGUMENT.rawValue, context: "Invalid minReconnectDelay value")) } do { _ = try maxReconnectDelay?.millisecondUInt64() } catch { - throw CommonRunTimeError.crtError(CRTError(code: AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue, + throw CommonRunTimeError.crtError(CRTError(code: AWS_ERROR_INVALID_ARGUMENT.rawValue, context: "Invalid maxReconnectDelay value")) } do { _ = try minConnectedTimeToResetReconnectDelay?.millisecondUInt64() } catch { - throw CommonRunTimeError.crtError(CRTError(code: AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue, + throw CommonRunTimeError.crtError(CRTError(code: AWS_ERROR_INVALID_ARGUMENT.rawValue, context: "Invalid minConnectedTimeToResetReconnectDelay value")) } do { _ = try pingTimeout?.millisecondUInt32() } catch { - throw CommonRunTimeError.crtError(CRTError(code: AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue, + throw CommonRunTimeError.crtError(CRTError(code: AWS_ERROR_INVALID_ARGUMENT.rawValue, context: "Invalid pingTimeout value")) } do { _ = try connackTimeout?.millisecondUInt32() } catch { - throw CommonRunTimeError.crtError(CRTError(code: AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue, + throw CommonRunTimeError.crtError(CRTError(code: AWS_ERROR_INVALID_ARGUMENT.rawValue, context: "Invalid connackTimeout value")) } if let ackTimeout { if ackTimeout < 0 || ackTimeout > Double(UInt32.max) { - throw CommonRunTimeError.crtError(CRTError(code: AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue, + throw CommonRunTimeError.crtError(CRTError(code: AWS_ERROR_INVALID_ARGUMENT.rawValue, context: "Invalid ackTimeout value")) } } diff --git a/Source/AwsCommonRuntimeKit/mqtt/Mqtt5Packets.swift b/Source/AwsCommonRuntimeKit/mqtt/Mqtt5Packets.swift index 12e15f71..0e250a9b 100644 --- a/Source/AwsCommonRuntimeKit/mqtt/Mqtt5Packets.swift +++ b/Source/AwsCommonRuntimeKit/mqtt/Mqtt5Packets.swift @@ -205,7 +205,7 @@ public class PublishPacket: CStruct { func validateConversionToNative() throws { if let messageExpiryInterval { if messageExpiryInterval < 0 || messageExpiryInterval > Double(UInt32.max) { - throw CommonRunTimeError.crtError(CRTError(code: AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue, + throw CommonRunTimeError.crtError(CRTError(code: AWS_ERROR_INVALID_ARGUMENT.rawValue, context: "Invalid sessionExpiryInterval value")) } } @@ -640,7 +640,7 @@ public class DisconnectPacket: CStruct { func validateConversionToNative() throws { if let sessionExpiryInterval { if sessionExpiryInterval < 0 || sessionExpiryInterval > Double(UInt32.max) { - throw CommonRunTimeError.crtError(CRTError(code: AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue, + throw CommonRunTimeError.crtError(CRTError(code: AWS_ERROR_INVALID_ARGUMENT.rawValue, context: "Invalid sessionExpiryInterval value")) } } diff --git a/Source/LibNative/CommonRuntimeError.h b/Source/LibNative/CommonRuntimeError.h index 3164b9b9..cbd6aa4c 100644 --- a/Source/LibNative/CommonRuntimeError.h +++ b/Source/LibNative/CommonRuntimeError.h @@ -11,16 +11,12 @@ #define AWS_DEFINE_ERROR_INFO_CRT_SWIFT(CODE, STR) [(CODE)-0x4400] = AWS_DEFINE_ERROR_INFO(CODE, STR, "aws-crt-swift") enum aws_swift_errors { - AWS_CRT_SWIFT_INVALID_ARGUMENT = AWS_ERROR_ENUM_BEGIN_RANGE(AWS_CRT_SWIFT_PACKAGE_ID), - AWS_CRT_SWIFT_MQTT_CLIENT_CLOSED, + AWS_CRT_SWIFT_MQTT_CLIENT_CLOSED = AWS_ERROR_ENUM_BEGIN_RANGE(AWS_CRT_SWIFT_PACKAGE_ID), AWS_CRT_SWIFT_ERROR_END_RANGE = AWS_ERROR_ENUM_END_RANGE(AWS_CRT_SWIFT_PACKAGE_ID), }; static struct aws_error_info s_crt_swift_errors[] = { - AWS_DEFINE_ERROR_INFO_CRT_SWIFT( - AWS_CRT_SWIFT_INVALID_ARGUMENT, - "An invalid argument was passed to a function."), AWS_DEFINE_ERROR_INFO_CRT_SWIFT( AWS_CRT_SWIFT_MQTT_CLIENT_CLOSED, "The Mqtt Client is closed.") diff --git a/Test/AwsCommonRuntimeKitTests/mqtt/Mqtt5ClientTests.swift b/Test/AwsCommonRuntimeKitTests/mqtt/Mqtt5ClientTests.swift index 7ed0c639..453b65dd 100644 --- a/Test/AwsCommonRuntimeKitTests/mqtt/Mqtt5ClientTests.swift +++ b/Test/AwsCommonRuntimeKitTests/mqtt/Mqtt5ClientTests.swift @@ -1046,7 +1046,7 @@ class Mqtt5ClientTests: XCBaseTestCase { return } catch CommonRunTimeError.crtError(let crtError) { print("expected keepAliveInterval error: \(crtError)") - XCTAssertEqual( crtError.code , (Int32)(AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue)) + XCTAssertEqual( crtError.code , (Int32)(AWS_ERROR_INVALID_ARGUMENT.rawValue)) } do { @@ -1059,7 +1059,7 @@ class Mqtt5ClientTests: XCBaseTestCase { return } catch CommonRunTimeError.crtError(let crtError) { print("expected sessionExpirtyInterval error: \(crtError)") - XCTAssertEqual( crtError.code , (Int32)(AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue)) + XCTAssertEqual( crtError.code , (Int32)(AWS_ERROR_INVALID_ARGUMENT.rawValue)) } do { @@ -1072,7 +1072,7 @@ class Mqtt5ClientTests: XCBaseTestCase { return } catch CommonRunTimeError.crtError(let crtError) { print("expected willDelayInterval error: \(crtError)") - XCTAssertEqual( crtError.code , (Int32)(AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue)) + XCTAssertEqual( crtError.code , (Int32)(AWS_ERROR_INVALID_ARGUMENT.rawValue)) } do { @@ -1084,7 +1084,7 @@ class Mqtt5ClientTests: XCBaseTestCase { return } catch CommonRunTimeError.crtError(let crtError) { print("expected minReconnectDelay error: \(crtError)") - XCTAssertEqual( crtError.code , (Int32)(AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue)) + XCTAssertEqual( crtError.code , (Int32)(AWS_ERROR_INVALID_ARGUMENT.rawValue)) } do { @@ -1096,7 +1096,7 @@ class Mqtt5ClientTests: XCBaseTestCase { return } catch CommonRunTimeError.crtError(let crtError) { print("expected minReconnectDelay error: \(crtError)") - XCTAssertEqual( crtError.code , (Int32)(AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue)) + XCTAssertEqual( crtError.code , (Int32)(AWS_ERROR_INVALID_ARGUMENT.rawValue)) } do { @@ -1108,7 +1108,7 @@ class Mqtt5ClientTests: XCBaseTestCase { return } catch CommonRunTimeError.crtError(let crtError) { print("expected minConnectedTimeToResetReconnectDelay error: \(crtError)") - XCTAssertEqual( crtError.code , (Int32)(AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue)) + XCTAssertEqual( crtError.code , (Int32)(AWS_ERROR_INVALID_ARGUMENT.rawValue)) } do { @@ -1120,7 +1120,7 @@ class Mqtt5ClientTests: XCBaseTestCase { return } catch CommonRunTimeError.crtError(let crtError) { print("expected pingTimeout error: \(crtError)") - XCTAssertEqual( crtError.code , (Int32)(AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue)) + XCTAssertEqual( crtError.code , (Int32)(AWS_ERROR_INVALID_ARGUMENT.rawValue)) } do { @@ -1132,7 +1132,7 @@ class Mqtt5ClientTests: XCBaseTestCase { return } catch CommonRunTimeError.crtError(let crtError) { print("expected connackTimeout error: \(crtError)") - XCTAssertEqual( crtError.code , (Int32)(AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue)) + XCTAssertEqual( crtError.code , (Int32)(AWS_ERROR_INVALID_ARGUMENT.rawValue)) } do { @@ -1144,7 +1144,7 @@ class Mqtt5ClientTests: XCBaseTestCase { return } catch CommonRunTimeError.crtError(let crtError) { print("expected ackTimeout error: \(crtError)") - XCTAssertEqual( crtError.code , (Int32)(AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue)) + XCTAssertEqual( crtError.code , (Int32)(AWS_ERROR_INVALID_ARGUMENT.rawValue)) } } @@ -1179,7 +1179,7 @@ class Mqtt5ClientTests: XCBaseTestCase { return } catch CommonRunTimeError.crtError(let crtError) { print("expected sessionExpiryInterval error: \(crtError)") - XCTAssertEqual( crtError.code , (Int32)(AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue)) + XCTAssertEqual( crtError.code , (Int32)(AWS_ERROR_INVALID_ARGUMENT.rawValue)) } } @@ -1217,7 +1217,7 @@ class Mqtt5ClientTests: XCBaseTestCase { return } catch CommonRunTimeError.crtError(let crtError) { print("expected messageExpiryInterval error:\(crtError)") - XCTAssertEqual( crtError.code , (Int32)(AWS_CRT_SWIFT_INVALID_ARGUMENT.rawValue)) + XCTAssertEqual( crtError.code , (Int32)(AWS_ERROR_INVALID_ARGUMENT.rawValue)) } }