Skip to content

Commit

Permalink
Catch filesystem exception during output of dependencies delta.
Browse files Browse the repository at this point in the history
When the frontend server attempts to compile dart code with an invalid
import (perhaps due to a missing entry in the .packages file), it will
get stuck in a bad state due to attempting to output said invalid import
uri as a new dependency.

Instead failures here should probably be caught and ignored, since the error messages are already reported through the existing diagnostics.

See also:

  - #36481

To reproduce this case:

1. Run the flutter gallery application (device unimportant).
2. Add an import for
`package:flutter_localizations/flutter_localizations.dart` in
`lib/main.dart`.
3. Request hot reload.

Before change:

```
Compiler message:
Error: Could not resolve the package 'flutter_localizations' in 'package:flutter_localizations/flutter_localizations.dart'.
lib/gallery/home.dart:12:8: Error: Not found: 'package:flutter_localizations/flutter_localizations.dart'
import 'package:flutter_localizations/flutter_localizations.dart';
       ^
Unhandled exception:
FileSystemException(uri=org-dartlang-untranslatable-uri:package%3Aflutter_localizations%2Fflutter_localizations.dart; message=StandardFileSystem only supports file:* and data:* URIs)
<asynchronous suspension>
<asynchronous suspension>
<asynchronous suspension>
<asynchronous suspension>
<asynchronous suspension>
```

It then gets stuck as from the perspective of the flutter tool the
reload request never completed.

After change:

```
Compiler message:
Error: Could not resolve the package 'flutter_localizations' in 'package:flutter_localizations/flutter_localizations.dart'.
lib/gallery/home.dart:12:8: Error: Not found: 'package:flutter_localizations/flutter_localizations.dart'
import 'package:flutter_localizations/flutter_localizations.dart';
       ^
Performing hot reload...
Reloaded 4 of 617 libraries in 837ms.

```

Change-Id: Ibb72624c492747a9339b15cb0b064edad8ebe4b8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/113135
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Zach Anderson <zra@google.com>
  • Loading branch information
jonahwilliams authored and commit-bot@chromium.org committed Aug 15, 2019
1 parent 9ae1d02 commit d8462dd
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pkg/vm/lib/frontend_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -441,11 +441,20 @@ class FrontendCompiler implements CompilerInterface {
if (previouslyReportedDependencies.contains(uri)) {
continue;
}
_outputStream.writeln('+${await asFileUri(_fileSystem, uri)}');
try {
_outputStream.writeln('+${await asFileUri(_fileSystem, uri)}');
} on FileSystemException {
// Ignore errors from invalid import uris.
}
}
for (Uri uri in previouslyReportedDependencies) {
if (!uris.contains(uri)) {
if (uris.contains(uri)) {
continue;
}
try {
_outputStream.writeln('-${await asFileUri(_fileSystem, uri)}');
} on FileSystemException {
// Ignore errors from invalid import uris.
}
}
previouslyReportedDependencies = uris;
Expand Down

1 comment on commit d8462dd

@DikshaCT27
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this by removing import dart:html from my file which is causing the error. One can trace this by reading the unhandled exception error with the file name with an error message.

Please sign in to comment.