You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[flutter_tools] ArgumentError: Invalid argument(s) (onError): The error handler of Future.catchError must return a value of the future's type #114031
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)
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
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).
// 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.voidmain() {
Future<dynamic>.delayed(Duration.zero).then((value) {
throwException('Crash');
}).catchError((e) {
print('caught');
});
}
// doesn't crash because we provide the type parameter `void` to `.then()`voidmain() {
Future<dynamic>.delayed(Duration.zero).then<void>((value) {
throwException('Crash');
}).catchError((e) {
print('caught');
});
}
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.
@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)
@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.
@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.
@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
@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
Activity
christopherfujino commentedon Oct 25, 2022
cc @jmagman
philos3 commentedon Nov 3, 2022
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)???
christopherfujino commentedon Nov 3, 2022
I'm not sure I understand your question. Are you asking why the error message tells you that there are "Invalid arguments"?
christopherfujino commentedon Nov 3, 2022
Never mind, I think I understand your question. The reason you're hitting this is because (I think) the callback to
catchErroris supposed to return a value of the type of the Future (in this case, I think dynamic).christopherfujino commentedon Nov 3, 2022
@philos3 I got this minimal reproducible example:
christopherfujino commentedon Nov 11, 2022
Closing this as a duplicate of #105750 (which was fixed in #115184)
github-actions commentedon Nov 25, 2022
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 -vand a minimal reproduction of the issue.6 remaining items
christopherfujino commentedon Jan 31, 2023
Increasing the priority as this is still one of the top crashers on stable/3.7.0
DanTup commentedon Feb 2, 2023
@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)
christopherfujino commentedon Feb 2, 2023
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.
christopherfujino commentedon Feb 4, 2023
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.
christopherfujino commentedon Feb 4, 2023
Most instances (but not all) will be fixed by #119977
christopherfujino commentedon Feb 6, 2023
@DanTup can you try to repro at b8f5394 ? I'm guessing you'll hit a different crash, which I still need to fix.
DanTup commentedon Feb 6, 2023
@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):No additional info if running with
-vv:christopherfujino commentedon Feb 6, 2023
Thanks, I will open a new issue for this. Done #120114
jmagman commentedon Feb 7, 2023
@christopherfujino it seems like
catchErroris quite a footgun, maybe we should forbid its use in the tool à la https://github.com/flutter/flutter/blob/e627e8d84147cbb58e2fad38415c805410917ce0/packages/flutter_tools/test/integration.shard/forbidden_imports_test.dart ?christopherfujino commentedon Feb 7, 2023
agreed
jmagman commentedon Feb 7, 2023
Created #120146.