Skip to content

[flutter_tools] ArgumentError: Invalid argument(s) (onError): The error handler of Future.catchError must return a value of the future's type #114031

Description

@christopherfujino

On beta/3.4.0-34.1.pre

Command: flutter debug-adapter

ArgumentError: Invalid argument(s) (onError): The error handler of Future.catchError must return a value of the future's type
at _FutureListener.handleError(future_impl.dart:181)
at Future._propagateToListeners.handleError(future_impl.dart:779)
at Future._propagateToListeners(future_impl.dart:800)
at Future._completeError(future_impl.dart:575)
at _rootRunBinary(zone.dart:1422)
at _CustomZone.runBinary(zone.dart:1314)
at _FutureListener.handleError(future_impl.dart:162)
at Future._propagateToListeners.handleError(future_impl.dart:779)
at Future._propagateToListeners(future_impl.dart:800)
at Future._completeError(future_impl.dart:575)
at _rootRunBinary(zone.dart:1422)
at _CustomZone.runBinary(zone.dart:1314)
at _FutureListener.handleError(future_impl.dart:162)
at Future._propagateToListeners.handleError(future_impl.dart:779)
at Future._propagateToListeners(future_impl.dart:800)
at Future._completeError(future_impl.dart:575)
at _rootRunBinary(zone.dart:1422)
at _CustomZone.runBinary(zone.dart:1314)
at _FutureListener.handleError(future_impl.dart:162)
at Future._propagateToListeners.handleError(future_impl.dart:779)
at Future._propagateToListeners(future_impl.dart:800)
at Future._completeError(future_impl.dart:575)
at Future._asyncCompleteError.<anonymous closure>(future_impl.dart:666)
at _rootRun(zone.dart:1398)
at _CustomZone.run(zone.dart:1300)
at _CustomZone.runGuarded(zone.dart:1208)
at _CustomZone.bindCallbackGuarded.<anonymous closure>(zone.dart:1248)
at _microtaskLoop(schedule_microtask.dart:40)
at _startMicrotaskLoop(schedule_microtask.dart:49)
at _runPendingImmediateCallback(isolate_patch.dart:122)
at _RawReceivePortImpl._handleMessage(isolate_patch.dart:193)

Activity

  1. added
    toolAffects the "flutter" command-line tool. See also t: labels.
    P2Important issues not at the top of the work list
    on Oct 25, 2022
  2. christopherfujino commented on Oct 25, 2022

    @christopherfujino
    ContributorAuthor
  3. philos3 commented on Nov 3, 2022

    @philos3

    Future.delayed(const Duration(seconds: 1))
    .whenComplete(
    () => Future.delayed(const Duration(seconds: 1)).then((value) {
    throw Exception("主动抛出异常333333");
    }, onError: (e) {
    print("333333=========onError==${e.toString()}");
    }).catchError((e) {
    print("333333===catchError=0000=======${e.toString()}");
    }))
    .catchError((e) {
    print("333333====catchError=======${e.toString()}");
    });

    print messsage:
    333333===catchError=0000=======Exception: 主动抛出异常333333
    333333====catchError=======Invalid argument(s) (onError): The error handler of Future.catchError must return a value of the future's type

    why print Invalid argument(s) (onError)???

  4. christopherfujino commented on Nov 3, 2022

    @christopherfujino
    ContributorAuthor

    why print Invalid argument(s) (onError)???

    I'm not sure I understand your question. Are you asking why the error message tells you that there are "Invalid arguments"?

  5. christopherfujino commented on Nov 3, 2022

    @christopherfujino
    ContributorAuthor

    why print Invalid argument(s) (onError)???

    I'm not sure I understand your question. Are you asking why the error message tells you that there are "Invalid arguments"?

    Never mind, I think I understand your question. The reason you're hitting this is because (I think) the callback to catchError is supposed to return a value of the type of the Future (in this case, I think dynamic).

  6. christopherfujino commented on Nov 3, 2022

    @christopherfujino
    ContributorAuthor

    @philos3 I got this minimal reproducible example:

    // this will throw a runtime ArgumentError because the compiler infers the return type of `.then()` to be `Future<Never>` because it sees it will always throw.
    void main() {
      Future<dynamic>.delayed(Duration.zero).then((value) {
        throw Exception('Crash');
      }).catchError((e) {
        print('caught');
      });
    }
    // doesn't crash because we provide the type parameter `void` to `.then()`
    void main() {
      Future<dynamic>.delayed(Duration.zero).then<void>((value) {
        throw Exception('Crash');
      }).catchError((e) {
        print('caught');
      });
    }
  7. added
    P1High-priority issues at the top of the work list
    and removed
    P2Important issues not at the top of the work list
    on Nov 8, 2022
  8. christopherfujino commented on Nov 11, 2022

    @christopherfujino
    ContributorAuthor

    Closing this as a duplicate of #105750 (which was fixed in #115184)

  9. github-actions commented on Nov 25, 2022

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  10. locked as resolved and limited conversation to collaborators on Nov 25, 2022
  11. 6 remaining items

  12. christopherfujino commented on Jan 31, 2023

    @christopherfujino
    ContributorAuthor

    Increasing the priority as this is still one of the top crashers on stable/3.7.0

  13. DanTup commented on Feb 2, 2023

    @DanTup
    Contributor

    @christopherfujino are the current crashes still coming from DAP, or somewhere else? (almost nobody should be on the new DAP for Flutter right now, it's still defaulted to off)

  14. christopherfujino commented on Feb 2, 2023

    @christopherfujino
    ContributorAuthor

    @christopherfujino are the current crashes still coming from DAP, or somewhere else? (almost nobody should be on the new DAP for Flutter right now, it's still defaulted to off)

    Hard to tell, since the stacktrace is no help. I have been assuming it's not coming from DAP, since you flipped it off. After what you found, I need to re-evaluate a bunch of tool usage of .catchError.

  15. christopherfujino commented on Feb 4, 2023

    @christopherfujino
    ContributorAuthor

    @christopherfujino are the current crashes still coming from DAP, or somewhere else? (almost nobody should be on the new DAP for Flutter right now, it's still defaulted to off)

    Hard to tell, since the stacktrace is no help. I have been assuming it's not coming from DAP, since you flipped it off. After what you found, I need to re-evaluate a bunch of tool usage of .catchError.

    Actually, I can see the top-level command, and I don't see debug-adapter among the 20 or so I spot checked. I think we're good.

  16. christopherfujino commented on Feb 4, 2023

    @christopherfujino
    ContributorAuthor

    Most instances (but not all) will be fixed by #119977

  17. christopherfujino commented on Feb 6, 2023

    @christopherfujino
    ContributorAuthor

    @DanTup can you try to repro at b8f5394 ? I'm guessing you'll hit a different crash, which I still need to fix.

  18. DanTup commented on Feb 6, 2023

    @DanTup
    Contributor

    @christopherfujino running the command from #119432 (yes | flutter doctor --android-licenses) results in the "correct" exception showing up now (I've no idea what the other warning output is about):

    danny@Dannys-MacBook-Pro flutter % yes | flutter doctor --android-licenses
    Warning: This version only understands SDK XML versions up to 2 but an SDK XML file of version 3 was encountered. This can happen if you use versions of Android Studio and the command-line tools that were released at different times.
    Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
    Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
    Warning: unexpected element (uri:"", local:"extension-level"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
    Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
    Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}api-level>
    Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
    Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
    Warning: unexpected element (uri:"", local:"extension-level"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
    Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
    Warning: Errors limit exceeded. To receive all errors set com.sun.xml.bind logger to FINEST level.
    Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}api-level>
    All SDK package licenses accepted.======] 100% Computing updates...             
    
    Echoing stdin to the licenses subprocess failed:
    SocketException: Write failed (OS Error: Broken pipe, errno = 32), port = 0
    #0      _NativeSocket.write (dart:io-patch/socket_patch.dart:1195:34)
    #1      _RawSocket.write (dart:io-patch/socket_patch.dart:1938:15)
    #2      _Socket._write (dart:io-patch/socket_patch.dart:2385:18)
    #3      _SocketStreamConsumer.write (dart:io-patch/socket_patch.dart:2128:26)
    #4      _Socket._onData (dart:io-patch/socket_patch.dart:2356:19)
    #5      _rootRunUnary (dart:async/zone.dart:1414:13)
    #6      _CustomZone.runUnary (dart:async/zone.dart:1307:19)
    #7      _CustomZone.runUnaryGuarded (dart:async/zone.dart:1216:7)
    #8      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
    #9      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
    #10     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19)
    #11     _StreamController._add (dart:async/stream_controller.dart:648:7)
    #12     _StreamController.add (dart:async/stream_controller.dart:596:5)
    #13     new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1876:23)
    #14     _NativeSocket.issueWriteEvent.issue (dart:io-patch/socket_patch.dart:1354:14)
    #15     _NativeSocket.issueWriteEvent (dart:io-patch/socket_patch.dart:1361:7)
    #16     _NativeSocket.multiplex (dart:io-patch/socket_patch.dart:1396:13)
    #17     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:192:26)
    

    No additional info if running with -vv:

    Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
    Warning: Errors limit exceeded. To receive all errors set com.sun.xml.bind logger to FINEST level.
    Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}api-level>
    All SDK package licenses accepted.======] 100% Computing updates...             
    
    [+1385 ms] Echoing stdin to the licenses subprocess failed:
    [   +2 ms] SocketException: Write failed (OS Error: Broken pipe, errno = 32), port = 0
               #0      _NativeSocket.write (dart:io-patch/socket_patch.dart:1195:34)
               #1      _RawSocket.write (dart:io-patch/socket_patch.dart:1938:15)
               #2      _Socket._write (dart:io-patch/socket_patch.dart:2385:18)
               #3      _SocketStreamConsumer.write (dart:io-patch/socket_patch.dart:2128:26)
               #4      _Socket._onData (dart:io-patch/socket_patch.dart:2356:19)
               #5      _rootRunUnary (dart:async/zone.dart:1414:13)
               #6      _CustomZone.runUnary (dart:async/zone.dart:1307:19)
               #7      _CustomZone.runUnaryGuarded (dart:async/zone.dart:1216:7)
               #8      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
               #9      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
               #10     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19)
               #11     _StreamController._add (dart:async/stream_controller.dart:648:7)
               #12     _StreamController.add (dart:async/stream_controller.dart:596:5)
               #13     new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1876:23)
               #14     _NativeSocket.issueWriteEvent.issue (dart:io-patch/socket_patch.dart:1354:14)
               #15     _NativeSocket.issueWriteEvent (dart:io-patch/socket_patch.dart:1361:7)
               #16     _NativeSocket.multiplex (dart:io-patch/socket_patch.dart:1396:13)
               #17     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:192:26)
               
    [  +13 ms] "flutter doctor" took 4,125ms.
    [   +2 ms] Running 0 shutdown hooks
    [        ] Shutdown hooks complete
    [   +1 ms] exiting with code 0
    
  19. christopherfujino commented on Feb 6, 2023

    @christopherfujino
    ContributorAuthor

    @christopherfujino running the command from #119432 (yes | flutter doctor --android-licenses) results in the "correct" exception showing up now (I've no idea what the other warning output is about):

    danny@Dannys-MacBook-Pro flutter % yes | flutter doctor --android-licenses
    Warning: This version only understands SDK XML versions up to 2 but an SDK XML file of version 3 was encountered. This can happen if you use versions of Android Studio and the command-line tools that were released at different times.
    Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
    Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
    Warning: unexpected element (uri:"", local:"extension-level"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
    Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
    Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}api-level>
    Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
    Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
    Warning: unexpected element (uri:"", local:"extension-level"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
    Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
    Warning: Errors limit exceeded. To receive all errors set com.sun.xml.bind logger to FINEST level.
    Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}api-level>
    All SDK package licenses accepted.======] 100% Computing updates...             
    
    Echoing stdin to the licenses subprocess failed:
    SocketException: Write failed (OS Error: Broken pipe, errno = 32), port = 0
    #0      _NativeSocket.write (dart:io-patch/socket_patch.dart:1195:34)
    #1      _RawSocket.write (dart:io-patch/socket_patch.dart:1938:15)
    #2      _Socket._write (dart:io-patch/socket_patch.dart:2385:18)
    #3      _SocketStreamConsumer.write (dart:io-patch/socket_patch.dart:2128:26)
    #4      _Socket._onData (dart:io-patch/socket_patch.dart:2356:19)
    #5      _rootRunUnary (dart:async/zone.dart:1414:13)
    #6      _CustomZone.runUnary (dart:async/zone.dart:1307:19)
    #7      _CustomZone.runUnaryGuarded (dart:async/zone.dart:1216:7)
    #8      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
    #9      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
    #10     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19)
    #11     _StreamController._add (dart:async/stream_controller.dart:648:7)
    #12     _StreamController.add (dart:async/stream_controller.dart:596:5)
    #13     new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1876:23)
    #14     _NativeSocket.issueWriteEvent.issue (dart:io-patch/socket_patch.dart:1354:14)
    #15     _NativeSocket.issueWriteEvent (dart:io-patch/socket_patch.dart:1361:7)
    #16     _NativeSocket.multiplex (dart:io-patch/socket_patch.dart:1396:13)
    #17     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:192:26)
    

    No additional info if running with -vv:

    Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
    Warning: Errors limit exceeded. To receive all errors set com.sun.xml.bind logger to FINEST level.
    Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}api-level>
    All SDK package licenses accepted.======] 100% Computing updates...             
    
    [+1385 ms] Echoing stdin to the licenses subprocess failed:
    [   +2 ms] SocketException: Write failed (OS Error: Broken pipe, errno = 32), port = 0
               #0      _NativeSocket.write (dart:io-patch/socket_patch.dart:1195:34)
               #1      _RawSocket.write (dart:io-patch/socket_patch.dart:1938:15)
               #2      _Socket._write (dart:io-patch/socket_patch.dart:2385:18)
               #3      _SocketStreamConsumer.write (dart:io-patch/socket_patch.dart:2128:26)
               #4      _Socket._onData (dart:io-patch/socket_patch.dart:2356:19)
               #5      _rootRunUnary (dart:async/zone.dart:1414:13)
               #6      _CustomZone.runUnary (dart:async/zone.dart:1307:19)
               #7      _CustomZone.runUnaryGuarded (dart:async/zone.dart:1216:7)
               #8      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
               #9      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
               #10     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19)
               #11     _StreamController._add (dart:async/stream_controller.dart:648:7)
               #12     _StreamController.add (dart:async/stream_controller.dart:596:5)
               #13     new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1876:23)
               #14     _NativeSocket.issueWriteEvent.issue (dart:io-patch/socket_patch.dart:1354:14)
               #15     _NativeSocket.issueWriteEvent (dart:io-patch/socket_patch.dart:1361:7)
               #16     _NativeSocket.multiplex (dart:io-patch/socket_patch.dart:1396:13)
               #17     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:192:26)
               
    [  +13 ms] "flutter doctor" took 4,125ms.
    [   +2 ms] Running 0 shutdown hooks
    [        ] Shutdown hooks complete
    [   +1 ms] exiting with code 0
    

    Thanks, I will open a new issue for this. Done #120114

  20. jmagman commented on Feb 7, 2023

    @jmagman
    Member
  21. christopherfujino commented on Feb 7, 2023

    @christopherfujino
    ContributorAuthor
  22. jmagman commented on Feb 7, 2023

    @jmagman
    Member

    Created #120146.

  23. added
    P0Critical issues such as a build break or regression
    and removed on Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P0Critical issues such as a build break or regressiontoolAffects 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