<div dir="ltr">Is this a naming collision? Do multiple modules defined a Transaction.Error.NotFound?<div><br><div>For instance, in your passing case, is the <span style="font-size:12.8px">Transaction.Error.NotFound that is caught a Z.Transaction.Error.NotFound, or one in your local app module (i.e. CLI.Transaction.Error.NotFound).</span></div></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">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.</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Just a thought.</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Ian</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 31, 2016 at 12:44 AM, Joakim Hassila via swift-users <span dir="ltr"><<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Ok, I am stumped and wanted to see if anyone had any ideas on how to troubleshoot this.<br>
<br>
Short background:<br>
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.<br>
<br>
I’m testing this on OS X w. XCode 7.3.1 using Swift 2.2 all with Debug builds.<br>
<br>
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.<br>
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.<br>
<br>
So the issue is when I am looking at throwing errors from Z, as X can’t properly pattern match the errors.<br>
<br>
Short snippet showing relevant code and output from a testrun:<br>
<br>
>From the command line tool X:<br>
——<br>
func localThrow () throws -> Void<br>
{<br>
throw Transaction.Error.NotFound<br>
}<br>
<br>
do{<br>
try localThrow() // try throwing from embedded local function<br>
} catch Transaction.Error.NotFound { // this matches as expectd<br>
print("Transaction not found (local)")<br>
} catch {<br>
print("Unknown error (local)")<br>
}<br>
<br>
let transaction2 = Transaction()<br>
<br>
do {<br>
try transaction2.errorNow() // try throwing from framework<br>
} catch Transaction.Error.NotFound { // this never matches!<br>
print("Transaction not found (framework)")<br>
} catch {<br>
print("Unknown error (framework)")<br>
}<br>
——<br>
<br>
In the framework Z, we have:<br>
——<br>
import W<br>
<br>
public class Transaction {<br>
// ...<br>
}<br>
<br>
public extension Transaction {<br>
<br>
public final func errorNow() throws -> Void<br>
{<br>
throw Transaction.Error.NotFound<br>
}<br>
}<br>
——<br>
<br>
and the output when run is:<br>
——<br>
Transaction not found (local)<br>
Unknown error (framework)<br>
——<br>
<br>
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:<br>
<br>
error = (Z.Transaction.Error) NotFound<br>
<br>
When single-stepping the local call, ‘error’ does not seem to be populated properly but it matches as it should.<br>
<br>
I tried minimizing it with a simple app (not command line though) and framework, but there it works as expected of course…<br>
<br>
Anyone have any ideas what might be the problem?<br>
<br>
Cheers,<br>
<br>
Joakim<br>
<br>
<br>
_______________________________________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
</blockquote></div><br></div>