diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TestHarness/AuthCodableImplementations/Cognito/Response/ForgotPasswordOutputResponse+Codable.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TestHarness/AuthCodableImplementations/Cognito/Response/ForgotPasswordOutputResponse+Codable.swift index fb8cb14202..0c35be603a 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TestHarness/AuthCodableImplementations/Cognito/Response/ForgotPasswordOutputResponse+Codable.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TestHarness/AuthCodableImplementations/Cognito/Response/ForgotPasswordOutputResponse+Codable.swift @@ -41,7 +41,10 @@ extension CognitoIdentityProviderClientTypes.CodeDeliveryDetailsType: Decodable let container = try decoder.container(keyedBy: CodingKeys.self) try self.init( attributeName: container.decodeIfPresent(String.self, forKey: .attributeName), - deliveryMedium: container.decodeIfPresent(CognitoIdentityProviderClientTypes.DeliveryMediumType.self, forKey: .deliveryMedium), + deliveryMedium: container.decodeIfPresent( + CognitoIdentityProviderClientTypes.DeliveryMediumType.self, + forKey: .deliveryMedium + ), destination: container.decodeIfPresent(String.self, forKey: .destination) ) } diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TestHarness/AuthCodableImplementations/Cognito/Response/InitiateAuthOutputResponse+Codable.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TestHarness/AuthCodableImplementations/Cognito/Response/InitiateAuthOutputResponse+Codable.swift index 4a8cfc59ce..155fd62081 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TestHarness/AuthCodableImplementations/Cognito/Response/InitiateAuthOutputResponse+Codable.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TestHarness/AuthCodableImplementations/Cognito/Response/InitiateAuthOutputResponse+Codable.swift @@ -61,7 +61,10 @@ extension CognitoIdentityProviderClientTypes.AuthenticationResultType: Decodable accessToken: container.decodeIfPresent(String.self, forKey: .accessToken), expiresIn: container.decode(Int.self, forKey: .expiresIn), idToken: container.decodeIfPresent(String.self, forKey: .idToken), - newDeviceMetadata: container.decodeIfPresent(CognitoIdentityProviderClientTypes.NewDeviceMetadataType.self, forKey: .newDeviceMetadata), + newDeviceMetadata: container.decodeIfPresent( + CognitoIdentityProviderClientTypes.NewDeviceMetadataType.self, + forKey: .newDeviceMetadata + ), refreshToken: container.decodeIfPresent(String.self, forKey: .refreshToken), tokenType: container.decodeIfPresent(String.self, forKey: .tokenType) ) diff --git a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Endpoint/PinpointClientTypes+Codable.swift b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Endpoint/PinpointClientTypes+Codable.swift index 57f83ce97d..c1964cb00b 100644 --- a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Endpoint/PinpointClientTypes+Codable.swift +++ b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Endpoint/PinpointClientTypes+Codable.swift @@ -5,8 +5,8 @@ // SPDX-License-Identifier: Apache-2.0 // -import Foundation import AWSPinpoint +import Foundation extension PinpointClientTypes.EndpointLocation: Codable, Equatable { private enum CodingKeys: CodingKey { @@ -18,7 +18,10 @@ extension PinpointClientTypes.EndpointLocation: Codable, Equatable { case region } - public static func == (lhs: PinpointClientTypes.EndpointLocation, rhs: PinpointClientTypes.EndpointLocation) -> Bool { + public static func == ( + lhs: PinpointClientTypes.EndpointLocation, + rhs: PinpointClientTypes.EndpointLocation + ) -> Bool { return lhs.city == rhs.city && lhs.country == rhs.country && lhs.latitude == rhs.latitude @@ -62,7 +65,10 @@ extension PinpointClientTypes.EndpointDemographic: Codable, Equatable { case timezone } - public static func == (lhs: PinpointClientTypes.EndpointDemographic, rhs: PinpointClientTypes.EndpointDemographic) -> Bool { + public static func == ( + lhs: PinpointClientTypes.EndpointDemographic, + rhs: PinpointClientTypes.EndpointDemographic + ) -> Bool { return lhs.appVersion == rhs.appVersion && lhs.locale == rhs.locale && lhs.make == rhs.make @@ -97,7 +103,6 @@ extension PinpointClientTypes.EndpointDemographic: Codable, Equatable { try container.encodeIfPresent(platform, forKey: .platform) try container.encodeIfPresent(platformVersion, forKey: .platformVersion) try container.encodeIfPresent(timezone, forKey: .timezone) - } } @@ -107,7 +112,10 @@ extension PinpointClientTypes.EndpointUser: Codable, Equatable { case userId } - public static func == (lhs: PinpointClientTypes.EndpointUser, rhs: PinpointClientTypes.EndpointUser) -> Bool { + public static func == ( + lhs: PinpointClientTypes.EndpointUser, + rhs: PinpointClientTypes.EndpointUser + ) -> Bool { return lhs.userAttributes == rhs.userAttributes && lhs.userId == rhs.userId } diff --git a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Support/Utils/AmplifyStringConvertible.swift b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Support/Utils/AmplifyStringConvertible.swift index bcdf84b078..97632cbb29 100644 --- a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Support/Utils/AmplifyStringConvertible.swift +++ b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Support/Utils/AmplifyStringConvertible.swift @@ -7,6 +7,7 @@ import Foundation +/// Conforming to this protocol automatically adds support to "prettify" the type when printing its value. protocol AmplifyStringConvertible: CustomStringConvertible {} extension AmplifyStringConvertible { @@ -14,13 +15,18 @@ extension AmplifyStringConvertible { return prettyDescription(for: self) } - private func prettyDescription(for object: Any, level: UInt = 1) -> String { + private func prettyDescription( + for object: Any, + level: UInt = 1 + ) -> String { return prettyDescription(for: object, level: level) { result, indentation in switch object { case let dictionary as Dictionary: // Dictionaries follow the format: "": for (key, value) in dictionary { - result.append(contentsOf: "\n\(indentation)\"\(key)\": \(description(for: value, withLevel: level)),") + result.append( + contentsOf: "\n\(indentation)\"\(key)\": \(description(for: value, withLevel: level))," + ) } case let collection as any Collection: // Other collections follow the format: , , ..., @@ -31,13 +37,19 @@ extension AmplifyStringConvertible { // Other objects follow the format: : for child in Mirror(reflecting: object).children { guard let label = child.label else { continue } - result.append(contentsOf: "\n\(indentation)\(label): \(description(for: child.value, withLevel: level)),") + result.append( + contentsOf: "\n\(indentation)\(label): \(description(for: child.value, withLevel: level))," + ) } } } } - private func prettyDescription(for object: Any, level: UInt = 1, contentsBuilder: (_ result: inout String, _ indentation: String) -> Void) -> String { + private func prettyDescription( + for object: Any, + level: UInt = 1, + contentsBuilder: (_ result: inout String, _ indentation: String) -> Void + ) -> String { var contents = "" contentsBuilder(&contents, indentation(forLevel: level)) if contents.isEmpty { @@ -52,8 +64,11 @@ extension AmplifyStringConvertible { ) } - private func description(for value: Any, withLevel level: UInt) -> String { - let unwrappedValue = unwrappedValue(from: value) // This is to prevent Optionals from printing with the prefix + private func description( + for value: Any, + withLevel level: UInt + ) -> String { + let unwrappedValue = unwrappedValue(from: value) switch unwrappedValue { case let stringValue as String: return stringValue.quoted @@ -100,7 +115,11 @@ extension AmplifyStringConvertible { } } - private func appendClosingTag(_ tag: String, to value: String, currentLevel level: UInt) -> String { + private func appendClosingTag( + _ tag: String, + to value: String, + currentLevel level: UInt + ) -> String { // Remove the last comma let result = value.hasSuffix(",") ? String(value.dropLast()) : value // As we're adding a closing tag, reduce one indentation level diff --git a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Dependency/TranscribeStreamingClientTypes+Decodable.swift b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Dependency/TranscribeStreamingClientTypes+Decodable.swift index d1ab4c647a..7579667a60 100644 --- a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Dependency/TranscribeStreamingClientTypes+Decodable.swift +++ b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Dependency/TranscribeStreamingClientTypes+Decodable.swift @@ -5,8 +5,8 @@ // SPDX-License-Identifier: Apache-2.0 // -import Foundation import AWSTranscribeStreaming +import Foundation extension TranscribeStreamingClientTypes.TranscriptEvent: Decodable { private enum CodingKeys: String, CodingKey { @@ -16,7 +16,10 @@ extension TranscribeStreamingClientTypes.TranscriptEvent: Decodable { public init(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) try self.init( - transcript: container.decode(TranscribeStreamingClientTypes.Transcript.self, forKey: .transcript) + transcript: container.decode( + TranscribeStreamingClientTypes.Transcript.self, + forKey: .transcript + ) ) } } @@ -49,12 +52,21 @@ extension TranscribeStreamingClientTypes.Result: Decodable { public init(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) try self.init( - alternatives: container.decodeIfPresent([TranscribeStreamingClientTypes.Alternative].self, forKey: .alternatives), + alternatives: container.decodeIfPresent( + [TranscribeStreamingClientTypes.Alternative].self, + forKey: .alternatives + ), channelId: container.decodeIfPresent(String.self, forKey: .channelId), endTime: container.decode(Double.self, forKey: .endTime), isPartial: container.decode(Bool.self, forKey: .isPartial), - languageCode: container.decodeIfPresent(TranscribeStreamingClientTypes.LanguageCode.self, forKey: .languageCode), - languageIdentification: container.decodeIfPresent([TranscribeStreamingClientTypes.LanguageWithScore].self, forKey: .languageIdentification), + languageCode: container.decodeIfPresent( + TranscribeStreamingClientTypes.LanguageCode.self, + forKey: .languageCode + ), + languageIdentification: container.decodeIfPresent( + [TranscribeStreamingClientTypes.LanguageWithScore].self, + forKey: .languageIdentification + ), resultId: container.decodeIfPresent(String.self, forKey: .resultId), startTime: container.decode(Double.self, forKey: .startTime) ) @@ -71,8 +83,14 @@ extension TranscribeStreamingClientTypes.Alternative: Decodable { public init(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) try self.init( - entities: container.decodeIfPresent([TranscribeStreamingClientTypes.Entity].self, forKey: .entities), - items: container.decodeIfPresent([TranscribeStreamingClientTypes.Item].self, forKey: .items), + entities: container.decodeIfPresent( + [TranscribeStreamingClientTypes.Entity].self, + forKey: .entities + ), + items: container.decodeIfPresent( + [TranscribeStreamingClientTypes.Item].self, + forKey: .items + ), transcript: container.decodeIfPresent(String.self, forKey: .transcript) ) } @@ -137,7 +155,10 @@ extension TranscribeStreamingClientTypes.LanguageWithScore: Decodable { public init(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) try self.init( - languageCode: container.decodeIfPresent(TranscribeStreamingClientTypes.LanguageCode.self, forKey: .languageCode), + languageCode: container.decodeIfPresent( + TranscribeStreamingClientTypes.LanguageCode.self, + forKey: .languageCode + ), score: container.decode(Double.self, forKey: .score) ) } diff --git a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/UploadPartInput+presignURL.swift b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/UploadPartInput+presignURL.swift index 1b2809e007..6f7b708b0f 100644 --- a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/UploadPartInput+presignURL.swift +++ b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/UploadPartInput+presignURL.swift @@ -15,7 +15,10 @@ import SmithyRetries // swiftlint:disable identifier_name // swiftlint:disable line_length extension UploadPartInput { - public func customPresignURL(config: S3Client.S3ClientConfiguration, expiration: Foundation.TimeInterval) async throws -> Foundation.URL? { + func customPresignURL( + config: S3Client.S3ClientConfiguration, + expiration: Foundation.TimeInterval + ) async throws -> Foundation.URL? { let serviceName = "S3" let input = self let client: (SmithyHTTPAPI.HTTPRequest, Smithy.Context) async throws -> SmithyHTTPAPI.HTTPResponse = { (_, _) in @@ -86,7 +89,11 @@ struct UploadPartPresignedMiddleware: Smithy.RequestMessageSerializer { let id: Swift.String = "UploadPartPresignedMiddleware" - func apply(input: InputType, builder: SmithyHTTPAPI.HTTPRequestBuilder, attributes: Smithy.Context) throws { + func apply( + input: InputType, + builder: SmithyHTTPAPI.HTTPRequestBuilder, + attributes: Smithy.Context + ) throws { builder.withQueryItem(.init( name: "x-id", value: "UploadPart") diff --git a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/StorageMultipartUploadSession.swift b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/StorageMultipartUploadSession.swift index f5dc25f76a..73fe7bcc67 100644 --- a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/StorageMultipartUploadSession.swift +++ b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/StorageMultipartUploadSession.swift @@ -44,7 +44,7 @@ class StorageMultipartUploadSession { private let onEvent: AWSS3StorageServiceBehavior.StorageServiceMultiPartUploadEventHandler private let transferTask: StorageTransferTask - private var cancelationFailure: (any Error)? + private var cancelationError: (any Error)? = nil init(client: StorageMultipartUploadClient, bucket: String, @@ -247,14 +247,10 @@ class StorageMultipartUploadSession { case .completed: onEvent(.completed(())) case .aborting(_, let error): - cancelationFailure = error + cancelationError = error try abort() case .aborted(_, let error): - if let cancelationFailure { - onEvent(.failed(StorageError(error: cancelationFailure))) - } else { - onEvent(.failed(StorageError.unknown("Unable to upload", error))) - } + onEvent(.failed(StorageError.unknown("Unable to upload", cancelationError ?? error))) case .failed(_, _, let error): onEvent(.failed(StorageError(error: error))) default: diff --git a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/StorageServiceSessionDelegate.swift b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/StorageServiceSessionDelegate.swift index 0ca4447988..58e079b3f7 100644 --- a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/StorageServiceSessionDelegate.swift +++ b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/StorageServiceSessionDelegate.swift @@ -120,7 +120,8 @@ extension StorageServiceSessionDelegate: URLSessionTaskDelegate { if response.isErrorRetriable { logURLSessionActivity("Task can be retried.") } - // For multipart uploads, we need to handle the upload part failure + + // For multipart uploads, we need to handle the upload part failure when the session is not aborted if case .multiPartUploadPart(let uploadId, let partNumber) = transferTask.transferType, let multipartUploadSession = storageService.findMultipartUploadSession(uploadId: uploadId), !multipartUploadSession.isAborted { diff --git a/Package.swift b/Package.swift index ac5ecb6d7f..898db2e500 100644 --- a/Package.swift +++ b/Package.swift @@ -406,7 +406,7 @@ let predictionsTargets: [Target] = [ name: "AWSPredictionsPluginUnitTests", dependencies: ["AWSPredictionsPlugin"], path: "AmplifyPlugins/Predictions/Tests/AWSPredictionsPluginUnitTests", - resources: [.copy("TestResources/TestImages")] + resources: [.copy("TestResources/TestImages") ] ), .target( name: "CoreMLPredictionsPlugin",