dev_compiler icon indicating copy to clipboard operation
dev_compiler copied to clipboard

Improve Error / Exception interop between Dart and JS

Open vsmenon opened this issue 10 years ago • 2 comments

We want Dart stack traces to log nicely on the dev tools console. E.g., console.log of a JS Error gives a nice, clickable stack trace. Logging a Dart Error or Exception does not.

One possibility is to overlay Dart Error and Exception types onto the JS Error as much as possible. This is non-trivial as both are interfaces that can and are implemented instead of extended.

There may be other options short of overlaying as well.

vsmenon avatar Jul 14 '15 19:07 vsmenon

For interfaces, we already have some magic for dealing with some of them. Iterable comes to mind (to make it implement ES6 iterator protocol), as well as extension interfaces like Pattern and List (because they are implemented by native types which can't use normal method names).

jmesserly avatar Jul 14 '15 20:07 jmesserly

an example of why this would help: debugging our tests using Karma, I don't get a stack trace:

DEBUG [web-server]: serving (cached): /Users/jmesserly/src/dev_compiler/lib/runtime/_generators.js
Chrome 46.0.2457 (Mac OS X 10.10.4) language syncstar_yield_test FAILED
    Error: the object {
      "message": "Expect.listEquals(at index 1, expected: <-1>, actual: <undefined>) fails"
    } was thrown, throw an Error :)
Chrome 46.0.2457 (Mac OS X 10.10.4): Executed 26 of 26 (1 FAILED) (3.658 secs / 0.06 secs)

if our exceptions were JS Errors, it would presumably display the stack "for free"

edit: the throw an Error :) comment is cute huh?

jmesserly avatar Jul 17 '15 18:07 jmesserly