Skip to content

Unhandled exceptions in main() (before runApp) are written to stdout, not stderr #166246

Open
@DanTup

Description

@DanTup

Steps to reproduce

It's possible this is intended, but the issue raised at Dart-Code/Dart-Code#5468 about errors not being shown as red error text in VS Code is because there's no distinction between error and non-error output (prior to runApp, after which point we usually get "structured errors" from Flutter that we can format better).

  1. Create a Flutter app that throws in main (I think this would happen for Firebase config errors, for example):
    void main() {
      throw Exception("Firebase not initialized");
    }
  2. Run in a way that lets you tell the difference between stdout and stderr
    For example on Windows,
    flutter run -d windows 2>&1 | % { $_ -is [System.Management.Automation.ErrorRecord] ? "stderr: $_" : "stdout: $_" }

Actual results

The exception is written to stdout, whereas a similar exception in Dart would be written to stderr. stderr output in VS Code would appear as red/error, whereas stdout does not:

Flutter output:
Image

Flutter output in VS Code debug console:
Image

Dart output:
Image

Dart output in VS Code debug console:
Image

Logs

No response

Flutter Doctor output

PS D:\Dev> flutter doctor -v
[!] Flutter (Channel master, 3.31.0-1.0.pre.227, on Microsoft Windows [Version 10.0.26100.3476], locale en-GB) [3.9s]
    • Flutter version 3.31.0-1.0.pre.227 on channel master at D:\Dev\Google\Flutter\Flutter main
    ! Warning: `dart` on your path resolves to D:\Tools\Dart\Stable\bin\dart.exe, which is not inside your current Flutter SDK checkout at
      D:\Dev\Google\Flutter\Flutter main. Consider adding D:\Dev\Google\Flutter\Flutter main\bin to the front of your path.
    ! Upstream repository git@github.com:DanTup/flutter.git is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to git@github.com:DanTup/flutter.git to dismiss this error.
    • Framework revision 46969e531b (6 days ago), 2025-03-25 07:54:22 -0700
    • Engine revision 46969e531b
    • Dart version 3.8.0 (build 3.8.0-222.0.dev)
    • DevTools version 2.45.0-dev.0
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and
      upgrades.

[✓] Windows Version (11 Pro 64-bit, 24H2, 2009) [972ms]

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0-rc3) [2.5s]
    • Android SDK at C:\Users\danny\AppData\Local\Android\sdk
    • Platform android-35, build-tools 35.0.0-rc3
    • 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 21.0.5+-12932927-b750.29)
    • All Android licenses accepted.

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

[✓] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.10.5) [54ms]
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.10.35122.118
    • Windows 10 SDK version 10.0.22621.0

[✓] Android Studio (version 2024.2) [13ms]
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.5+-12932927-b750.29)

[✓] VS Code (version 1.98.2) [12ms]
    • VS Code at C:\Users\danny\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.107.20250303

[✓] VS Code (version 1.93.0-insider) [11ms]
    • VS Code at C:\Users\danny\AppData\Local\Programs\Microsoft VS Code Insiders
    • Flutter extension version 3.105.20250203

[✓] Connected device (3 available) [108ms]
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.26100.3476]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 134.0.6998.178
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 133.0.3065.92

[✓] Network resources [574ms]
    • All expected network resources are available.

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectfound in release: 3.29Found to occur in 3.29found in release: 3.31Found to occur in 3.31has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions