Skip to content

Exceptions from Future do not contain original call site #8656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sethladd opened this issue Feb 20, 2013 · 7 comments
Closed

Exceptions from Future do not contain original call site #8656

sethladd opened this issue Feb 20, 2013 · 7 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. closed-duplicate Closed in favor of an existing report

Comments

@sethladd
Copy link
Contributor

Consider this code:

import 'dart:async';

Future doItLater() {
  //return new Future.immediate('dart');
  return new Future.immediateError(new StateError('doh!'));
}

main() {
  doItLater().then(print);
}

When you run it, you get:

sethladd:~/dart/simpletests/bin$ dart asyncexception.dart
Uncaught Error: Bad state: doh!
Unhandled exception:
Bad state: doh!

­0 _FutureImpl._scheduleUnhandledError.<anonymous closure> (dart:async:334:9)

­1 Timer.Timer.<anonymous closure> (dart:async-patch:11:15)

­2 _Timer._createTimerHandler._handleTimeout (dart:io:7240:28)

­3 _Timer._createTimerHandler._handleTimeout (dart:io:7248:7)

­4 _Timer._createTimerHandler.<anonymous closure> (dart:io:7256:23)

­5 _ReceivePortImpl._handleMessage (dart:isolate-patch:40:92)

Problem:

The stack trace does not include any reference to the line of code that actually generated the error.

This makes debugging Dart really difficult.

(submitted on behalf of a partner who is building a Dart app for his job)

@sethladd
Copy link
Contributor Author

(not sure how to triage, starting with VM as first guess)

@gbracha
Copy link
Contributor

gbracha commented Feb 20, 2013

Added Duplicate label.
Marked as being merged into #4061.

@munificent
Copy link
Member

Marked as being merged into #7040.

@a-siva
Copy link
Contributor

a-siva commented Feb 28, 2013

Something like this could be done to get more context about the original call site:

import 'dart:async';

String getCurrentStackTrace() {
  try {
    throw "";
  } catch(e, s) {
    return "$s";
  }
}

Future doItLater() {
  var s = getCurrentStackTrace();
  return new Future.immediateError(new StateError('doh! @­ $s'));
}

main() {
  doItLater().then(print);
}

Executing this I get:
Uncaught Error: Bad state: doh! @­ #­0 getCurrentStackTrace (file:///tmp/junk2.dart:5:5)
#­0 doItLater (file:///tmp/junk2.dart:12:31)
#­1 main (file:///tmp/junk2.dart:17:12)

Unhandled exception:
Bad state: doh! @­ #­0 getCurrentStackTrace (file:///tmp/junk2.dart:5:5)
#­0 doItLater (file:///tmp/junk2.dart:12:31)
#­1 main (file:///tmp/junk2.dart:17:12)

#­0 _FutureImpl._scheduleUnhandledError.<anonymous closure> (dart:async:348:9)
#­1 Timer.run.<anonymous closure> (dart:async:2172:21)
#­2 Timer.run.<anonymous closure> (dart:async:2179:13)
#­3 Timer.Timer.<anonymous closure> (dart:async-patch:11:15)
#­4 _Timer._createTimerHandler._handleTimeout (dart:io:5930:28)
#­5 _Timer._createTimerHandler._handleTimeout (dart:io:5938:7)
#­6 _Timer._createTimerHandler.<anonymous closure> (dart:io:5946:23)
#­7 _ReceivePortImpl._handleMessage (dart:isolate-patch:40:92)

@sethladd
Copy link
Contributor Author

Hi Siva,

How does this work when you can't edit doItLater? That is, you don't own it and it's a 3rd party library. (I understand that all Dart apps are just text files, but it's not good practice to start editing dependencies.)

Also, doesn't this assume I know where the exception is happening in the first place? If I knew that, I wouldn't have to add the special getCurrentStackTrace() function. :)

Thoughts?

Thanks!

@a-siva
Copy link
Contributor

a-siva commented Feb 28, 2013

For the more generic case that you describe one would have to implement a subclass of Future which would have the additional functionality of storing the stack trace for later use. I think a mechanism like that is outside the scope of the Dart VM.

@sethladd
Copy link
Contributor Author

Thanks Siva, I'll ask the lib team about this.

@sethladd sethladd added Type-Defect area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. closed-duplicate Closed in favor of an existing report labels Feb 28, 2013
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. closed-duplicate Closed in favor of an existing report
Projects
None yet
Development

No branches or pull requests

4 participants