Skip to content

DevTools has trouble reading multipart requests #9626

@helomri

Description

@helomri

When I send a multipart request to upload a file and I try to look at the "Request" section of the request, DevTools throws an error in the console and does keeps loading forever. Also, when one of those requests is sent, Devtools fails to download the requests as .har or .json.
Here's the error :

[zoneGuarded]: FormatException: Invalid UTF-8 byte (at offset 998)
org-dartlang-sdk:///dart-sdk/lib/_internal/js_runtime/lib/js_helper.dart 1376:19       wrapException
org-dartlang-sdk:///dart-sdk/lib/_internal/js_shared/lib/convert_utf_patch.dart 103:7  _Utf8Decoder._convertGeneral
org-dartlang-sdk:///dart-sdk/lib/_internal/js_shared/lib/convert_utf_patch.dart 29:12  Utf8Decoder.convert
org-dartlang-sdk:///dart-sdk/lib/convert/utf.dart 58:10                                Utf8Codec.decode[function-entry$1]
../../../lib/src/shared/http/http_request_data.dart 104:25                             DartIOHttpRequestData.getFullRequestData
org-dartlang-sdk:///dart-sdk/lib/_internal/js_runtime/lib/async_patch.dart 339:19      _wrapJsFunctionForAsync
org-dartlang-sdk:///dart-sdk/lib/_internal/js_runtime/lib/async_patch.dart 365:23      _wrapJsFunctionForAsync.<anonymous function>
org-dartlang-sdk:///dart-sdk/lib/_internal/js_runtime/lib/async_patch.dart 313:7       _awaitOnObject.<anonymous function>
org-dartlang-sdk:///dart-sdk/lib/async/zone_root.dart 48:46                            _rootRunUnary
org-dartlang-sdk:///dart-sdk/lib/async/zone.dart 732:34                                _CustomZone.runUnary
org-dartlang-sdk:///dart-sdk/lib/async/future_impl.dart 186:29                         _FutureListener.handleValue
org-dartlang-sdk:///dart-sdk/lib/async/future_impl.dart 977:13                         _Future._propagateToListeners
org-dartlang-sdk:///dart-sdk/lib/async/future_impl.dart 720:5                          _Future._completeWithValue
org-dartlang-sdk:///dart-sdk/lib/_internal/js_runtime/lib/async_patch.dart 228:7       _AsyncAwaitCompleter.complete
org-dartlang-sdk:///dart-sdk/lib/_internal/js_runtime/lib/async_patch.dart 288:3       _asyncReturn
../../../lib/src/service/vm_service_wrapper.dart 359:13                                VmServiceWrapper._maybeLogWrappedFuture
org-dartlang-sdk:///dart-sdk/lib/_internal/js_runtime/lib/async_patch.dart 339:19      _wrapJsFunctionForAsync
org-dartlang-sdk:///dart-sdk/lib/_internal/js_runtime/lib/async_patch.dart 365:23      _wrapJsFunctionForAsync.<anonymous function>
org-dartlang-sdk:///dart-sdk/lib/_internal/js_runtime/lib/async_patch.dart 313:7       _awaitOnObject.<anonymous function>
org-dartlang-sdk:///dart-sdk/lib/async/zone_root.dart 48:46                            _rootRunUnary
org-dartlang-sdk:///dart-sdk/lib/async/zone.dart 732:34                                _CustomZone.runUnary
org-dartlang-sdk:///dart-sdk/lib/async/future_impl.dart 186:29                         _FutureListener.handleValue
org-dartlang-sdk:///dart-sdk/lib/async/future_impl.dart 977:13                         _Future._propagateToListeners
org-dartlang-sdk:///dart-sdk/lib/async/future_impl.dart 720:5                          _Future._completeWithValue
org-dartlang-sdk:///dart-sdk/lib/async/future_impl.dart 804:7                          _Future._asyncCompleteWithValue.<anonymous function>
org-dartlang-sdk:///dart-sdk/lib/async/zone_root.dart 35:12                            _rootRun
org-dartlang-sdk:///dart-sdk/lib/async/zone_root.dart 26:3                             _rootRun[function-entry$4]
org-dartlang-sdk:///dart-sdk/lib/async/zone.dart 725:34                                _CustomZone.run
org-dartlang-sdk:///dart-sdk/lib/async/zone.dart 625:7                                 _CustomZone.runGuarded
org-dartlang-sdk:///dart-sdk/lib/async/zone.dart 666:18                                _CustomZone.bindCallbackGuarded.<anonymous function>
org-dartlang-sdk:///dart-sdk/lib/async/schedule_microtask.dart 119:11                  _microtaskLoop
org-dartlang-sdk:///dart-sdk/lib/async/schedule_microtask.dart 49:5                    _startMicrotaskLoop
org-dartlang-sdk:///dart-sdk/lib/_internal/js_runtime/lib/async_patch.dart 55:10       _AsyncRun._initializeScheduleImmediate.internalCallback

This only happens when binary data is transferred (a PDF throws an error but not an MD file). An easy fix would be to put allowMalformed to true in the UtfDecoder for request and response decoding in order to try to display (or at least not throw an exception for) this malformed UTF8 data (which is not as this part of the request is binary, not UTF8.)

Here is the relevant piece of code :

_responseBody = utf8.decode(fullRequest.responseBody!);
_requestBody = utf8.decode(fullRequest.requestBody!);

I don't have the dev environment setup for DevTools to test this fix myself, but I believe this simple fix would fix the issue.


DevTools version: 2.54.0
IDE: IntelliJ-IDEA
Connected Device:
CPU / OS: x64 (64 bit) linux
Connected app type: Flutter native (debug build)
Dart Version: 3.12.0-14.0.dev
Flutter Version: 3.40.0-1.0.pre-518 / master
Framework / Engine: 73769a2206 / 73769a2206

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions