Skip to content
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

Isolate errors are not reported, if there is no error listener #26626

Open
alsemenov opened this issue Jun 7, 2016 · 6 comments
Open

Isolate errors are not reported, if there is no error listener #26626

alsemenov opened this issue Jun 7, 2016 · 6 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@alsemenov
Copy link
Contributor

alsemenov commented Jun 7, 2016

It is essential for any Dart environment to report all uncaught errors.
However, errors that occur inside running Isolate are not reported, the isolate is just suspended without any message to console. This is not programmer-friendly and complicates writing simple programs.
Consider the following example:

import "dart:isolate";
import "dart:async";

entryPoint(message) {
  print(await new Future.value(message));
}

main() async {
  await Isolate.spawn(entryPoint, "hello");
  await new Future.delayed(new Duration(seconds:1));
}

The code contains a mistake, await is used in a function entryPoint that is not marked as async.
The programmer would expect to get a message about the mistake. Instead he/she gets "nothing happens" situation and he/she has no clue about what is wrong. To investigate the problem it is necessary to add error listener to the isolate, like this:

import "dart:isolate";
import "dart:async";

entryPoint(message) {
  print(await new Future.value(message));
}

main() async {
  ReceivePort errorPort = new ReceivePort();
  errorPort.listen((e) => print(e));
  await Isolate.spawn(entryPoint, "hello", onError:errorPort.sendPort);
  await new Future.delayed(new Duration(seconds:1));
  errorPort.close();
}

Output:

['file:///D:/dev/dart/test4.dart': error: line 5 pos 15: ')' expected
print(await new Future.value(message));
^
, null]

The function main here has 2.5 times more lines of code.

Dart VM version: 1.16.1 (Tue May 24 12:27:14 2016) on "windows_x64"

@lrhn
Copy link
Member

lrhn commented Jun 7, 2016

That is surprising.
I think VM isolates used to print uncaught errors before terminating the isolate, even for spawned isolates. It should only omit printing the error if the isolate has an error listener.

The problem here might be that syntax errors are not normal errors, and they immediately terminate the isolate without going through the normal steps (#23684). Still, the error is reported if you do have an error listener, so it should be printed if you don't.

@lrhn lrhn added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. bug labels Jun 7, 2016
@a-siva
Copy link
Contributor

a-siva commented Jun 8, 2016

The embedder (command line dart) gets back control only from the main isolate when uncaught errors happen. So when the main isolate has such uncaught errors they are printed by the embedder.

In this example the error is happening in the spawned isolate and the embedder does not get any control back after the error happens and hence nothing is being reported. I think the error maybe written to the console if --trace-isolates flag is used.

@lrhn
Copy link
Member

lrhn commented Jun 8, 2016

Ok, so this is expected behavior?
I think all isolates should report uncaught errors on the console if they don't have an error listener added. If there is one or more error listeners, then the error should be considered handled that way and there is no need to print it.
(If the error listener has died or closed, that's a programming error, not something we can fix, although maybe the observatory knows enough to report when an isolate has attached error/exit listeners that aren't listening any more.)

@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) bug labels Jun 15, 2016
@floitschG
Copy link
Contributor

I can't find any --trace-isolates.

We had another user running into this. When there are no error-listeners we should just report the error on the console.

@aam
Copy link
Contributor

aam commented Apr 25, 2018

--trace-isolates is only available in debug build of dart vm: https://github.com/dart-lang/sdk/blob/master/runtime/vm/flag_list.h#L169

@aam
Copy link
Contributor

aam commented Apr 25, 2018

cc @rmacnak-google

dart-bot pushed a commit that referenced this issue Oct 17, 2018
…nhandled exceptions.

Given
```
import 'dart:isolate';
import 'dart:async';

void func(_) {
  throw new Exception('bad news');
}

void main() {
  ReceivePort receivePort;
  receivePort = new ReceivePort()..listen((_) { receivePort.close(); throw "more bad news"; } );
  Isolate.spawn(func, [], onExit: receivePort.sendPort);
}
```

Before this change only 'more bad news' will be printed on the stderr, after this change both 'bad news' and 'more bad news' will be printed out.

Before:
```
$ out/ReleaseX64/dart $DH/exc.dart

Unhandled exception:
more bad news

```

After:
```
$ out/ReleaseX64/dart $DH/exc.dart

Isolate is shutting down with the error: Unhandled exception:

Exception: bad news
Unhandled exception:
more bad news
```

Bug: #26626
Change-Id: Ief15f254837d9a02b93a6da655051fccf7c3dd2e
Reviewed-on: https://dart-review.googlesource.com/c/52680
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
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. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

6 participants