Is this a naming collision? Do multiple modules defined a Transaction.Error.NotFound?
For instance, in your passing case, is the Transaction.Error.NotFound that is caught a Z.Transaction.Error.NotFound, or one in your local app module (i.e. CLI.Transaction.Error.NotFound). If your CLI module has that defined, then that is what you are looking for in the catch statement. And since a Z.Transaction is not a CLI.Transaction it fails to catch it appropriately. Just a thought. Ian On Tue, May 31, 2016 at 12:44 AM, Joakim Hassila via swift-users < [email protected]> wrote: > Ok, I am stumped and wanted to see if anyone had any ideas on how to > troubleshoot this. > > Short background: > First off, I do have throwing/do/catch working perfectly fine in > Playgrounds as well as in standalone apps as well as in an app that links > with one of my own test frameworks, so I would hope this is not a simple > user error. > > I’m testing this on OS X w. XCode 7.3.1 using Swift 2.2 all with Debug > builds. > > I have a command line tool project "X" that links with two of my own Swift > frameworks, “Y" and “Z". Z also links with a pure C-language library, “W” > using a module map. > All of this works fine, as X can use entities from both Y and Z perfectly > fine, including indirect access of the C-library beneath. > > So the issue is when I am looking at throwing errors from Z, as X can’t > properly pattern match the errors. > > Short snippet showing relevant code and output from a testrun: > > From the command line tool X: > —— > func localThrow () throws -> Void > { > throw Transaction.Error.NotFound > } > > do{ > try localThrow() // try throwing from embedded local function > } catch Transaction.Error.NotFound { // this matches as expectd > print("Transaction not found (local)") > } catch { > print("Unknown error (local)") > } > > let transaction2 = Transaction() > > do { > try transaction2.errorNow() // try throwing from framework > } catch Transaction.Error.NotFound { // this never matches! > print("Transaction not found (framework)") > } catch { > print("Unknown error (framework)") > } > —— > > In the framework Z, we have: > —— > import W > > public class Transaction { > // ... > } > > public extension Transaction { > > public final func errorNow() throws -> Void > { > throw Transaction.Error.NotFound > } > } > —— > > and the output when run is: > —— > Transaction not found (local) > Unknown error (framework) > —— > > Setting a breakpoint and inspecting ‘error’ shows the following when > stepping over the call, and single stepping in the debugger shows that it > throws properly, it is just the matching that seems to fail. The Xcode lldb > inspector shows the error value as: > > error = (Z.Transaction.Error) NotFound > > When single-stepping the local call, ‘error’ does not seem to be populated > properly but it matches as it should. > > I tried minimizing it with a simple app (not command line though) and > framework, but there it works as expected of course… > > Anyone have any ideas what might be the problem? > > Cheers, > > Joakim > > > _______________________________________________ > swift-users mailing list > [email protected] > https://lists.swift.org/mailman/listinfo/swift-users >
_______________________________________________ swift-users mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-users
