<p dir="auto"><code class="notranslate">IOWebSocketChannel.connect</code> suffers from the problem described here:</p>
<p dir="auto"><a href="https://www.dartlang.org/guides/libraries/futures-error-handling#potential-problem-failing-to-register-error-handlers-early" rel="nofollow">https://www.dartlang.org/guides/libraries/futures-error-handling#potential-problem-failing-to-register-error-handlers-early</a></p>
<p dir="auto">When I use <code class="notranslate">connect</code> with a URL that can't be resolved (e.g. by having my wifi turned off), then I get an exception that can't be caught by <code class="notranslate">channel.stream.handleError(onError)</code>.</p>
<p dir="auto">All exceptions should be handleable by <code class="notranslate">stream.handleError</code>, particularly as this is what the docs promise: "If there's an error connecting, the channel's stream emits a WebSocketChannelException wrapping that error and then closes."</p>
<p dir="auto">ref: <a href="https://docs.flutter.io/flutter/web_socket_channel.io/IOWebSocketChannel/IOWebSocketChannel.connect.html" rel="nofollow">https://docs.flutter.io/flutter/web_socket_channel.io/IOWebSocketChannel/IOWebSocketChannel.connect.html</a></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="flutter: #0      new IOWebSocketChannel._withoutSocket.&lt;anonymous closure&gt; (package:web_socket_channel/io.dart:83:24)
#1      _invokeErrorHandler (dart:async/async_error.dart:13:29)
#2      _HandleErrorStream._handleError (dart:async/stream_pipe.dart:286:9)
#3      _ForwardingStreamSubscription._handleError (dart:async/stream_pipe.dart:168:13)
#4      _rootRunBinary (dart:async/zone.dart:1144:38)
#5      _CustomZone.runBinary (dart:async/zone.dart:1037:19)
#6      _CustomZone.runBinaryGuarded (dart:async/zone.dart:939:7)
#7      _BufferingStreamSubscription._sendError.sendError (dart:async/stream_impl.dart:355:15)
#8      _BufferingStreamSubscription._sendError (dart:async/stream_impl.dart:373:16)
#9      _BufferingStreamSubscription._addError (dart:async/stream_impl.dart:272:7)
#10     _SyncStreamController._sendError (dart:async/stream_controller.dart:767:19)
#11     _StreamController._addError (dart:async/stream_controller.dart:647:7)
#12     _rootRunBinary (dart:async/zone.dart:1144:38)"><pre class="notranslate"><code class="notranslate">flutter: #0      new IOWebSocketChannel._withoutSocket.&lt;anonymous closure&gt; (package:web_socket_channel/io.dart:83:24)
#1      _invokeErrorHandler (dart:async/async_error.dart:13:29)
#2      _HandleErrorStream._handleError (dart:async/stream_pipe.dart:286:9)
#3      _ForwardingStreamSubscription._handleError (dart:async/stream_pipe.dart:168:13)
#4      _rootRunBinary (dart:async/zone.dart:1144:38)
#5      _CustomZone.runBinary (dart:async/zone.dart:1037:19)
#6      _CustomZone.runBinaryGuarded (dart:async/zone.dart:939:7)
#7      _BufferingStreamSubscription._sendError.sendError (dart:async/stream_impl.dart:355:15)
#8      _BufferingStreamSubscription._sendError (dart:async/stream_impl.dart:373:16)
#9      _BufferingStreamSubscription._addError (dart:async/stream_impl.dart:272:7)
#10     _SyncStreamController._sendError (dart:async/stream_controller.dart:767:19)
#11     _StreamController._addError (dart:async/stream_controller.dart:647:7)
#12     _rootRunBinary (dart:async/zone.dart:1144:38)
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="flutter doctor -v
[✓] Flutter (Channel master, v0.7.1-pre.26, on Mac OS X 10.13.6 17G2208, locale en-GB)
    • Flutter version 0.7.1-pre.26 at /Users/steve/code/flutter
    • Framework revision 510c0eeaff (3 days ago), 2018-08-24 17:19:30 -0700
    • Engine revision 0914926014
    • Dart version 2.1.0-dev.1.0.flutter-ccb16f7282

[✓] Android toolchain - develop for Android devices (Android SDK 28.0.1)
    • Android SDK at /Users/steve/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.1
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.4.1, Build version 9F2000
    • ios-deploy 1.9.2
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 26.0.1
    • Dart plugin version 173.4700
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)

[✓] VS Code (version 1.26.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 2.17.1

[✓] Connected devices (1 available)
    • iPhone X • 1E0393AA-EF50-42AA-A244-3279599BE2C1 • ios • iOS 11.4 (simulator)

• No issues found!"><pre class="notranslate"><code class="notranslate">flutter doctor -v
[✓] Flutter (Channel master, v0.7.1-pre.26, on Mac OS X 10.13.6 17G2208, locale en-GB)
    • Flutter version 0.7.1-pre.26 at /Users/steve/code/flutter
    • Framework revision 510c0eeaff (3 days ago), 2018-08-24 17:19:30 -0700
    • Engine revision 0914926014
    • Dart version 2.1.0-dev.1.0.flutter-ccb16f7282

[✓] Android toolchain - develop for Android devices (Android SDK 28.0.1)
    • Android SDK at /Users/steve/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.1
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.4.1, Build version 9F2000
    • ios-deploy 1.9.2
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 26.0.1
    • Dart plugin version 173.4700
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)

[✓] VS Code (version 1.26.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 2.17.1

[✓] Connected devices (1 available)
    • iPhone X • 1E0393AA-EF50-42AA-A244-3279599BE2C1 • ios • iOS 11.4 (simulator)

• No issues found!
</code></pre></div>
<p dir="auto">Flutter crash report; please file at <a href="https://github.com/flutter/flutter/issues">https://github.com/flutter/flutter/issues</a>.</p>
<h2 dir="auto">command</h2>
<p dir="auto">flutter run</p>
<h2 dir="auto">exception</h2>
<p dir="auto">FormatException: FormatException: Bad UTF-8 encoding 0xb4 (at offset 96)</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#0      _Utf8Decoder.convert (dart:convert/utf.dart:574)
#1      _Utf8ConversionSink.addSlice (dart:convert/string_conversion.dart:345)
#2      _Utf8ConversionSink.add (dart:convert/string_conversion.dart:341)
#3      _ConverterStreamEventSink.add (dart:convert/chunked_conversion.dart:86)
#4      _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:120)
#5      _rootRunUnary (dart:async/zone.dart:1134)
#6      _CustomZone.runUnary (dart:async/zone.dart:1031)
#7      _CustomZone.runUnaryGuarded (dart:async/zone.dart:933)
#8      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:330)
#9      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:257)
#10     _StreamController&amp;&amp;_SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:762)
#11     _StreamController._add (dart:async/stream_controller.dart:638)
#12     _StreamController.add (dart:async/stream_controller.dart:584)
#13     _Socket._onData (dart:io-patch/socket_patch.dart:1654)
#14     _rootRunUnary (dart:async/zone.dart:1138)
#15     _CustomZone.runUnary (dart:async/zone.dart:1031)
#16     _CustomZone.runUnaryGuarded (dart:async/zone.dart:933)
#17     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:330)
#18     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:257)
#19     _StreamController&amp;&amp;_SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:762)
#20     _StreamController._add (dart:async/stream_controller.dart:638)
#21     _StreamController.add (dart:async/stream_controller.dart:584)
#22     new _RawSocket.&lt;anonymous closure&gt; (dart:io-patch/socket_patch.dart:1231)
#23     _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:784)
#24     _microtaskLoop (dart:async/schedule_microtask.dart:41)
#25     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50)
#26     _runPendingImmediateCallback (dart:isolate-patch/dart:isolate/isolate_patch.dart:111)
#27     _RawReceivePortImpl._handleMessage (dart:isolate-patch/dart:isolate/isolate_patch.dart:164)"><pre class="notranslate"><code class="notranslate">#0      _Utf8Decoder.convert (dart:convert/utf.dart:574)
#1      _Utf8ConversionSink.addSlice (dart:convert/string_conversion.dart:345)
#2      _Utf8ConversionSink.add (dart:convert/string_conversion.dart:341)
#3      _ConverterStreamEventSink.add (dart:convert/chunked_conversion.dart:86)
#4      _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:120)
#5      _rootRunUnary (dart:async/zone.dart:1134)
#6      _CustomZone.runUnary (dart:async/zone.dart:1031)
#7      _CustomZone.runUnaryGuarded (dart:async/zone.dart:933)
#8      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:330)
#9      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:257)
#10     _StreamController&amp;&amp;_SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:762)
#11     _StreamController._add (dart:async/stream_controller.dart:638)
#12     _StreamController.add (dart:async/stream_controller.dart:584)
#13     _Socket._onData (dart:io-patch/socket_patch.dart:1654)
#14     _rootRunUnary (dart:async/zone.dart:1138)
#15     _CustomZone.runUnary (dart:async/zone.dart:1031)
#16     _CustomZone.runUnaryGuarded (dart:async/zone.dart:933)
#17     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:330)
#18     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:257)
#19     _StreamController&amp;&amp;_SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:762)
#20     _StreamController._add (dart:async/stream_controller.dart:638)
#21     _StreamController.add (dart:async/stream_controller.dart:584)
#22     new _RawSocket.&lt;anonymous closure&gt; (dart:io-patch/socket_patch.dart:1231)
#23     _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:784)
#24     _microtaskLoop (dart:async/schedule_microtask.dart:41)
#25     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50)
#26     _runPendingImmediateCallback (dart:isolate-patch/dart:isolate/isolate_patch.dart:111)
#27     _RawReceivePortImpl._handleMessage (dart:isolate-patch/dart:isolate/isolate_patch.dart:164)
</code></pre></div>
<h2 dir="auto">flutter doctor</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[✓] Flutter (on Microsoft Windows [Version 10.0.16299.309], locale zh-CN, channel alpha)
    • Flutter version 0.0.21 at D:\flutter
    • Framework revision 2e449f06f0 (7 weeks ago), 2018-01-29 14:26:51 -0800
    • Engine revision 6921873c71
    • Tools Dart version 2.0.0-dev.16.0
    • Engine Dart version 2.0.0-edge.da1f52592ef73fe3afa485385cb995b9aec0181a

[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
    • Android SDK at C:\Users\Administrator\AppData\Local\Android\sdk
    • Android NDK at C:\Users\Administrator\AppData\Local\Android\sdk\ndk-bundle
    • Platform android-27, build-tools 27.0.3
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b01)

[✓] Android Studio (version 3.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b01)

[✓] IntelliJ IDEA Community Edition (version 2017.3)
    • Flutter plugin version 22.0.2
    • Dart plugin version 173.3942.31

[✓] Connected devices
    • MI 6 • dcf581ed • android-arm • Android 7.1.1 (API 25)
"><pre class="notranslate"><code class="notranslate">[✓] Flutter (on Microsoft Windows [Version 10.0.16299.309], locale zh-CN, channel alpha)
    • Flutter version 0.0.21 at D:\flutter
    • Framework revision 2e449f06f0 (7 weeks ago), 2018-01-29 14:26:51 -0800
    • Engine revision 6921873c71
    • Tools Dart version 2.0.0-dev.16.0
    • Engine Dart version 2.0.0-edge.da1f52592ef73fe3afa485385cb995b9aec0181a

[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
    • Android SDK at C:\Users\Administrator\AppData\Local\Android\sdk
    • Android NDK at C:\Users\Administrator\AppData\Local\Android\sdk\ndk-bundle
    • Platform android-27, build-tools 27.0.3
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b01)

[✓] Android Studio (version 3.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b01)

[✓] IntelliJ IDEA Community Edition (version 2017.3)
    • Flutter plugin version 22.0.2
    • Dart plugin version 173.3942.31

[✓] Connected devices
    • MI 6 • dcf581ed • android-arm • Android 7.1.1 (API 25)

</code></pre></div>