Hi everyone. I have an issue on the reject(error) part. Everything works fine on the debug mode. However on the release version crash occurs on that line. This error occurs on the iOS 10.3.1. Any help would be appreciated.
Thanks.
The problem occurs while casting Custom Error to NSError. I have posted an answer for this problem here: http://stackoverflow.com/questions/43225036/swift-3-1-crash-when-custom-error-is-converted-to-nserror-to-access-its-domain/43362207#43362207
I'm going to leave this open for other people to find.
Despite what the person in that SO thread said, casting a Swift.Error to NSError should not crash, even if you don鈥檛 implement the protocol. This is a feature of Swift鈥檚 toll-free bridging to Foundation that has existed since Error handling appeared.
I sincerely hope this is not a common issue :/
This bug should be reported at https://bugs.swift.com
A sample crash-case would be useful, or some example code, I assume you are using AnyPromise?
I am using PromiseKit like this way:
func fetchAvatar(user: String) -> Promise<UIImage> {
return Promise { fulfill, reject in
MyWebHelper.GET("\(user)/avatar") { data, err in
guard let data = data else { return reject(err) }
guard let img = UIImage(data: data) else { return reject(MyError.InvalidImage) }
guard let img.size.width > 0 else { return reject(MyError.ImageTooSmall) }
fulfill(img)
}
}
}
I will try to reproduce it with a simple project
What worked for me is to conform to CustomNSError protocol.
I think I have the same error. The crash seems to have to do with Error.isCancelledError. It crashes only in Release builds and the crash is at the catch. If I use the allErrors catch policy, it doesn't crash. Conforming my error to CustomNSError does fix the crashes as well.
I'll try to build a minimal crashing project.
Sigh, really need to run tests in debug AND release mode, sucks.
@pgrosslicht super thanks, your deduction has helped and I will push this hopeful fix:
if let ne = self as? CustomNSError {
return cancelledErrorIdentifiers.contains(ErrorPair(type(of: ne).errorDomain, ne.errorCode))
} else {
return false
}
Though trying to prove it works or not first.
Tests fail, not a fix. Since apparently NSError does not confirm to CustomNSError. FFS.
Also I cannot actually reproduce this crash. If I run our tests built release with the framework built release, no crashes occur. The tests run over these code paths.
So really I need a test case.
Is it possible this was fixed in the most recent Xcode 8.3.2 update?
@mxcl I have been able to build a minimal reproduction here: https://github.com/pgrosslicht/PromiseKitCrashReproduction
But it seems that this has been fixed in Xcode 8.3.2. The reproduction worked, then I updated and it stopped working. I removed the workaround from my original app and it worked there as well when compiled with Xcode 8.3.2. So if you want to test the crash, it only works with Xcode 8.3.1.
THE SAME
THE SAME
The same it鈥檚 fixed in Xcode 8.3.2 or the same it crashes?
The same it鈥檚 fixed in Xcode 8.3.2 or the same it crashes?
I have Xcode 8.3.2 and it crashes anyway with absolutely the same reason.
edit: It crashes in CorePromise/Error.swift line 145 in "release" build configuration only
Can you provide a testcase? Otherwise I can't verify any fix I attempt works.
Can you provide a testcase? Otherwise I can't verify any fix I attempt works.
Ok, I will do that and notify you in this thread after. As I see now, app crashes if PromiseKit getting the variable "isCancelledError". In other ways it doesn't crash
I have verified that the provided TestCase does not crash with 8.3.2.
I guess I will try to get hold of 8.3.1 again and see with that.
Yes, agree. I clean cache and try. It does not crash with 8.3.2
Yes, agree. I clean cache and try. It does not crash with 8.3.2
K, great news. I am downloading 8.3.1, just for thoroughness. Will leave open for 2 weeks so anyone else experiencing the crash can easily find this report.
Yes, thank you.
This is a common problem, not the xcode version of the problem, but other versions still crash.
If you are experiencing this bug with other versions of Xcode please open a new ticket so we can investigate.
Most helpful comment
What worked for me is to conform to
CustomNSErrorprotocol.