Skip to content

Handle flutter build errors when http imports are used #27103

@cbracken

Description

@cbracken

While they are supported in the standalone Dart VM, http/https URI schemes in import directives are unsupported in Flutter. When detected, we should emit a clear, actionable error message.

Repro instructions

flutter create example
cd example

Edit lib/main.dart to add an http/https import, such as:

import 'http://raw.githubusercontent.com/dart-lang/coverage/master/test/test_files/test_app_isolate.dart';

Run the app on an iOS/Android simulator/emulator:

flutter run -d iPhone

Behaviour

Expected behaviour: warning that HTTP/HTTPS imports are unsupported.

Actual behaviour:

% flutter run -d iPh
Oops; flutter has exited unexpectedly.
Sending crash report to Google.
Crash report sent (report ID: 6c9495d6fdcce621)
Crash report written to /Users/cbracken/src/deleteme/flutter_01.log;
please let us know at https://github.com/flutter/flutter/issues.

The result of flutter build ios is slightly better, though the error message is still somewhat misleading in that case:

    lib/main.dart:2:8: Error: Error when reading 'http://raw.githubusercontent.com/dart-lang/coverage/master/test/test_files/test_app_isolate.dart': StandardFileSystem only supports
    file:* and data:* URIs

    import 'http://raw.githubusercontent.com/dart-lang/coverage/master/test/test_files/test_app_isolate.dart';
           ^

Exception

UnsupportedError: Unsupported operation: Cannot extract a file path from a https URI

#0      _SimpleUri.toFilePath (dart:core/uri.dart:4587:7)
#1      DartDependencySetBuilder.build (package:flutter_tools/src/dart/dependencies.dart:91:58)
#2      HotRunner._refreshDartDependencies (package:flutter_tools/src/run_hot.dart:128:69)
<asynchronous suspension>
#3      HotRunner.run (package:flutter_tools/src/run_hot.dart:287:16)
<asynchronous suspension>
#4      RunCommand.runCommand (package:flutter_tools/src/commands/run.dart:392:37)
<asynchronous suspension>
#5      FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:551:18)
#6      _asyncThenWrapperHelper.<anonymous closure> (dart:async/runtime/libasync_patch.dart:77:64)
#7      _rootRunUnary (dart:async/zone.dart:1132:38)
#8      _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#9      _FutureListener.handleValue (dart:async/future_impl.dart:126:18)
#10     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:639:45)
#11     Future._propagateToListeners (dart:async/future_impl.dart:668:32)
#12     Future._complete (dart:async/future_impl.dart:473:7)
#13     _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
#14     _AsyncAwaitCompleter.complete (dart:async/runtime/libasync_patch.dart:28:18)
#15     _completeOnAsyncReturn (dart:async/runtime/libasync_patch.dart:294:13)
#16     RunCommand.usageValues (package:flutter_tools/src/commands/run.dart)
#17     _asyncThenWrapperHelper.<anonymous closure> (dart:async/runtime/libasync_patch.dart:77:64)
#18     _rootRunUnary (dart:async/zone.dart:1132:38)
#19     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#20     _FutureListener.handleValue (dart:async/future_impl.dart:126:18)
#21     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:639:45)
#22     Future._propagateToListeners (dart:async/future_impl.dart:668:32)
#23     Future._complete (dart:async/future_impl.dart:473:7)
#24     _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
#25     _AsyncAwaitCompleter.complete.<anonymous closure> (dart:async/runtime/libasync_patch.dart:33:20)
#26     _rootRun (dart:async/zone.dart:1124:13)
#27     _CustomZone.run (dart:async/zone.dart:1021:19)
#28     _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:947:23)
#29     _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#30     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#31     _runPendingImmediateCallback (dart:isolate/runtime/libisolate_patch.dart:115:13)
#32     _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:172:5)

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: new featureNothing broken; request for a new capabilitydependency: dartDart team may need to help ustoolAffects the "flutter" command-line tool. See also t: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions