diff --git a/ConcurrencyTests/PromiseTests.swift b/ConcurrencyTests/PromiseTests.swift index aa97ec6..07a8ad0 100644 --- a/ConcurrencyTests/PromiseTests.swift +++ b/ConcurrencyTests/PromiseTests.swift @@ -187,7 +187,7 @@ class PromiseTests: QuickSpec { expect(mappedFuture.isComplete).toEventually(beTrue()) expect(mappedFuture.succeeded).toEventually(beFalse()) expect(mappedFuture.failed).toEventually(beTrue()) - expect(item(mappedFuture.error, isA: NSError.self, and: {$0.domain == "Could not map value (3) to type String."})).toEventually(beTrue()) + expect(item(mappedFuture.error, isA: NSError.self, and:{ $0.description == "Concurrency: Could not map value (3) to type String." })).toEventually(beTrue()) expect(mappedFuture.value).toEventually(beNil()) } } diff --git a/Source/ConcurrencyHelpers.swift b/Source/ConcurrencyHelpers.swift index 858f2ca..08c0c71 100644 --- a/Source/ConcurrencyHelpers.swift +++ b/Source/ConcurrencyHelpers.swift @@ -8,8 +8,38 @@ import Foundation extension NSError { static func cantMap(value:T, toType: Q.Type) -> NSError { + return CantMapError(value: value, toType: toType) + } +} + +fileprivate class CantMapError: NSError { + + private var descriptionString: String + + init(value: T, toType: Q.Type) { let typeString = String(describing: type(of: Q.self)).replacingOccurrences(of: ".Type", with: "") - let description = "Could not map value (\(value)) to type \(typeString)." - return NSError(domain: description, code: 0, userInfo: nil) + let description = "Concurrency: Could not map value (\(value)) to type \(typeString)." + self.descriptionString = description + + super.init(domain: "com.concurrency.map", code: 0, userInfo: ["description" : description]) + } + + required init?(coder aDecoder: NSCoder) { + self.descriptionString = "Mapping Error" + + super.init(coder: aDecoder) + + if let unarchivedDescription = self.userInfo["description"] as? String { + self.descriptionString = unarchivedDescription + } + } + + override var description: String { + return descriptionString + } + + public static func ==(lhs: CantMapError, rhs: CantMapError) -> Bool { + return lhs.description == rhs.description } + }