Closed asinning closed 10 years ago
Hej, since lately, Chrome developer tools have a check box "Async" in the Call Stack panel on the "Sources" tab. Activating this check box should help! Greetings -Frank-
I'm not sure how the Chrome developer Tools will help with errors in the flash player plugin, did I miss something?
But I have something else for you, I'm writing this from memory so this may not run out of the box:
Assuming you are executing your swf in the debug player, you should find the one place in code, where no more thens are called with the failing promise and call the done
method on the promise.
this way, whenever a promise fails in a way that otherwise
catches the error, it will "rethrow" the error that occured in a way that it also contains the original stacktrace.
Does this help?
I'm not sure how the Chrome developer Tools will help with errors in the flash player plugin, did I miss something?
Yeah, you missed something, namely Jangaroo ;-), and it's been a long day, so I'm sorry I didn't mind the context. With Jangaroo, you can use Promise/AS3 from/in JavaScript (see https://github.com/fwienber/promise-as3/tree/jangaroo), and then (and only then, of course), Chrome developer tools' Async feature really helps. Sorry again.
When you attach a callback via then()
(or otherwise()
) it ends up being scheduled for execution on a future turn of the event loop. This ensures that program flow is the same regardless of whether a Promise is resolved or rejected immediately or in the future.
Consequence executes your scheduled callback within a try...catch block via the Consequence::transform()
method, where it will catch any Error, and propagate that Error as a rejection of the resulting Promise. (This is by design: every time you use then()
it returns a new Promise of the result as transformed by the specified callbacks - allowing for error recovery or propagation of errors triggered in subsequent processing of a previous result.)
So, the Error thrown in your handler is causing the Promise returned by your then()
call to reject with that Error. If you have no subsequent rejection handler, that rejection is goes unhandled - aka a "silent" rejection.
This is where the done()
method @karfau mentioned becomes useful. Each time you call then()
on a Promise, you are creating a new branch of a tree. When you call then()
and don't subsequently chain another then()/otherwise()/etc. method or return the resulting Promise, you can think of that as the terminating leaf node of that tree. Chain a done()
call off your then()
there. This adds a special rejection handler that rethrows the originating Error. The stacktrace will include the context where the original Error occurred.
There's more documentation about the done()
method in the README.
Hope that helps!
@fwienber That's pretty cool - didn't know anyone was using this library in that environment.
Thanks so much for the responses! This is very helpful.
On Thu, Sep 25, 2014 at 2:33 PM, John Yanarella notifications@github.com wrote:
@fwienber https://github.com/fwienber That's pretty cool - didn't know anyone was using this library in that environment.
— Reply to this email directly or view it on GitHub https://github.com/CodeCatalyst/promise-as3/issues/42#issuecomment-56871295 .
I don't know that I can use done() to overcome the problem I'm facing.
Here's what I'm doing:
promise .then( function(data:Data):void { doSomething(data); // this is throwing an error }) .otherwise( function(e:Error):void { tellTheUserAboutTheError(e); });
For the most part, this is working as needed. When the promise is rejected, it include a meaningful error which is shared with the user. However, when doSomething() throws an error I need a way to find the error.
My work around is to wrap doSomething() in a try/catch with a breakpoint in the catch. Is there a better way to do this with the scaffolding that Promise provides?
promise .then( function(data:Data):void { try { doSomething(data); // this is throwing an error } catch( e:Error ) { trace(e); // here is where I put my breakpoint } }) .otherwise( function(e:Error):void { tellTheUserAboutTheError(e); });
Thanks!
On Thu, Sep 25, 2014 at 4:27 PM, Andrew Sinning andrew.sinning@gmail.com wrote:
Thanks so much for the responses! This is very helpful.
On Thu, Sep 25, 2014 at 2:33 PM, John Yanarella notifications@github.com wrote:
@fwienber https://github.com/fwienber That's pretty cool - didn't know anyone was using this library in that environment.
— Reply to this email directly or view it on GitHub https://github.com/CodeCatalyst/promise-as3/issues/42#issuecomment-56871295 .
To recieve the exact Class and line where the error was thrown you need the look at the stacktrace.
I think there iis no better way then the one you point out to get the original error.
To get the stackTrace call the method getStacktrace()
on the error (or trace the returned String), only works in debug player.
another way would be to call do something directly under simlar conditions.
(Still not sure if I understood what you asked for)
This isn't exactly an "issue", but I am hoping you might shed some light on my problem. My program is throwing an error somewhere within a method called by the .then method of a fullfilled promise. When I put a breakpoint in my code, the stack-trace originates within a Timer which is calling execute() in an instance of the Consequence class. I need to find the real origin of the error, but I have no idea how to do this within the context of the promise. I've tried putting a breakpoint within the "CompletionAction.REJECT" case in Consequence.trigger, but that doesn't help at all either.
Thanks for any insight!