diff --git a/Source/AwsCommonRuntimeKit/sdkutils/CRTAWSProfileCollection.swift b/Source/AwsCommonRuntimeKit/sdkutils/CRTAWSProfileCollection.swift index d04a73f49..c47da9985 100644 --- a/Source/AwsCommonRuntimeKit/sdkutils/CRTAWSProfileCollection.swift +++ b/Source/AwsCommonRuntimeKit/sdkutils/CRTAWSProfileCollection.swift @@ -6,9 +6,9 @@ import AwsCSdkUtils public class CRTAWSProfileCollection { var rawValue: OpaquePointer - public init(fromFile path: String, - source: CRTAWSProfileSourceType, - allocator: Allocator = defaultAllocator) { + public init?(fromFile path: String, + source: CRTAWSProfileSourceType, + allocator: Allocator = defaultAllocator) { var finalizedPath = path if path.hasPrefix("~"), let homeDirectory = aws_get_home_directory(allocator.rawValue), @@ -16,9 +16,12 @@ public class CRTAWSProfileCollection { finalizedPath = homeDirectoryString + path.dropFirst() } let awsString = AWSString(finalizedPath, allocator: allocator) - self.rawValue = aws_profile_collection_new_from_file(allocator.rawValue, - awsString.rawValue, - source.rawValue) + guard let profilePointer = aws_profile_collection_new_from_file(allocator.rawValue, + awsString.rawValue, + source.rawValue) else { + return nil + } + self.rawValue = profilePointer } public init(fromBuffer buffer: ByteBuffer, @@ -28,9 +31,9 @@ public class CRTAWSProfileCollection { let byteCount = byteArray.count let byteBuf = byteArray.withUnsafeMutableBufferPointer { pointer -> aws_byte_buf in let byteBuf = aws_byte_buf(len: byteCount, - buffer: pointer.baseAddress, - capacity: byteCount, - allocator: allocator.rawValue) + buffer: pointer.baseAddress, + capacity: byteCount, + allocator: allocator.rawValue) return byteBuf } let pointer: UnsafePointer = fromPointer(ptr: byteBuf)