Skip to content

debugPrintStack throws an assertion error when printing the stack trace of a ParallelWaitError during tests #179018

Description

@ksatoudeveloper

Steps to reproduce

  1. Create a test file (e.g. parallel_wait_error_test.dart).
  2. Paste the Code sample below in the file.
  3. Run the test.

Expected results

debugPrintStack should print the stack trace without throwing any exceptions, even when called in a test environment.

Actual results

Running the test results in the assertion error.

Code sample

Code sample
import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  test(
    "debugPrintStack fails when printing the stack trace of a ParallelWaitError",
    () async {
      await (function1(), function2()).wait.then(
        (_) {},
        onError: (e, s) {
          // Printing the stack trace causes a failure.
          if (kDebugMode) {
            debugPrintStack(
              label: e.toString(),
              stackTrace: s,
            ); // ❌ Unexpected failure
          }
        },
      );
    },
  );
}

Future<void> function1() async {
  await Future<void>.delayed(const Duration(seconds: 1));
}

Future<void> function2() async {
  await Future<void>.delayed(const Duration(seconds: 1));
  throw Exception("function2");
}

Screenshots or Video

No response

Logs

Logs
ParallelWaitError: Exception: function2
'package:flutter/src/foundation/stack_frame.dart': Failed assertion: line 197 pos 7: 'line != '===== asynchronous gap ==========================='': Got a stack frame from package:stack_trace, where a vm or web frame was expected. This can happen if FlutterError.demangleStackTrace was not set in an environment that propagates non-standard stack traces to the framework, such as during tests.
dart:core                                               _AssertionError._throwNew
package:flutter/src/foundation/stack_frame.dart 197:7   StackFrame.fromStackTraceLine
dart:core                                               Iterable.toList
package:flutter/src/foundation/stack_frame.dart 85:10   StackFrame.fromStackString
package:flutter/src/foundation/assertions.dart 1092:54  FlutterError.defaultStackFilter
package:flutter/src/foundation/assertions.dart 1241:27  debugPrintStack
test\asynchronous_gap_test.dart 13:13                   main.<fn>.<fn>
===== asynchronous gap ===========================
dart:async                                              Future.then
test\asynchronous_gap_test.dart 8:45                    main.<fn>

Flutter Doctor output

Doctor output
flutter doctor -v
[√] Flutter (Channel stable, 3.38.2, on Microsoft Windows [Version 10.0.26200.7171], locale ja-JP) [125ms]
    • Flutter version 3.38.2 on channel stable at C:\Users\kame2\fvm\versions\3.38.2
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f5a8537f90 (6 days ago), 2025-11-18 09:27:21 -0500
    • Engine revision b5990e5ccc
    • Dart version 3.10.0
    • DevTools version 2.51.1
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, omit-legacy-version-file,
      enable-lldb-debugging

[√] Windows Version (11 Pro 64-bit, 25H2, 2009) [547ms]

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [1,021ms]
    • Android SDK at C:\Users\kame2\AppData\Local\Android\sdk
    • Emulator version 32.1.15.0 (build_id 10696886) (CL:N/A)
    • Platform android-36, build-tools 34.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-10027231)
    • All Android licenses accepted.

[√] Chrome - develop for the web [6ms]
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop Windows apps [5ms]
    X Visual Studio not installed; this is necessary to develop Windows apps.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Connected device (3 available) [142ms]
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.26200.7171]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 142.0.7444.176
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 142.0.3595.94

[√] Network resources [455ms]
    • All expected network resources are available.

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: debuggingDebugging, breakpoints, expression evaluationa: error messageError messages from the Flutter frameworka: tests"flutter test", flutter_test, or one of our testsfound in release: 3.38Found to occur in 3.38found in release: 3.39Found to occur in 3.39frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework teamworkaround availableThere is a workaround available to overcome the issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions