0

I'am trying to use EventSource with Dart.

var source = new EventSource('/myUrl');
source.on.error.add((Event e) => print('error'));
source.on.message.add((MessageEvent me)  => print(me.data));

The messages are well received, but 'error' is always print. How can I got more information about this error ? I tryied to use ErrorEvent instead of Event but it fail because this event is not a ErrorEvent

  • 1
    In the second line above, did you try print(e) in the handler? - the listing above prints the string 'error' rather than the contents of Event e – Chris Buckett Aug 07 '12 at 12:28
  • Yes I tried and it just print : Instance of '_EventImpl@65b10ff' – Nicolas François Aug 07 '12 at 14:11
  • I tryed it and it print `error` and when I try : `source.on.error.add((ErrorEvent e) => print(e.message));` I got this error `Exception: type '_EventImpl@65b10ff' is not a subtype of type 'ErrorEvent' of 'e'.`. Maybe there is a bug with ErrorEvent ? – Nicolas François Aug 07 '12 at 15:57

1 Answers1

1

I don't have an event source to test with, but I can help you answer your question, "How can I got more information about this error?"

Change:

source.on.error.add((Event e) => print('error'));

To:

source.on.error.add((e) {
  print('error');
});

Then, set a breakpoint on the line with print. This will let you inspect the local variable e when you debug your application in Dartium.

You can also use dart2js to compile the application to JavaScript and the Chrome's JavaScript debugger to learn more about e. Search for "error" in the generated JavaScript in the debugger to figure out where to put the breakpoint.

Another trick that is sometimes helpful is to change the code to:

source.on.error.add((int e) => print('error'));

e is not an int, so DartEditor will give you a warning, telling you what type e really is. Then, you can use that type. Next, Command-click on that type to look at the source code for it.

My best advice is to try to use Chrome's JavaScript debugger and debug the problem from there. That's helped me isolate this sort of problem in the past.

Shannon -jj Behrens
  • 4,910
  • 2
  • 19
  • 24