Skip to content

[CP-stable][Tool] Handle DTD connection failures gracefully in widget-preview#187323

Merged
auto-submit[bot] merged 1 commit into
flutter:flutter-3.44-candidate.0from
flutteractionsbot:cp-stable-610419e4e1c701fc8383aa36ae8d65dad12c8103
Jun 5, 2026
Merged

[CP-stable][Tool] Handle DTD connection failures gracefully in widget-preview#187323
auto-submit[bot] merged 1 commit into
flutter:flutter-3.44-candidate.0from
flutteractionsbot:cp-stable-610419e4e1c701fc8383aa36ae8d65dad12c8103

Conversation

@flutteractionsbot

@flutteractionsbot flutteractionsbot commented May 29, 2026

Copy link
Copy Markdown
Contributor

This pull request is created by automatic cherry pick workflow
Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request.

Issue Link:

What is the link to the issue this cherry-pick is addressing?

#187322

Impact Description:

What is the impact (ex. visual jank on Samsung phones, app crash, cannot ship an iOS app)?
Does it impact development (ex. flutter doctor crashes when Android Studio is installed),
or the shipping of production apps (the app crashes on launch).
This information is for domain experts and release engineers to understand the consequences of saying yes or no to the cherry pick.

This issue impacts development. When using flutter widget-preview start, if the Dart Tooling Daemon (DTD) is not running or fails to connect at startup, the tool crashes with an unhandled RpcException or StateError showing a full stack trace instead of exiting gracefully. Additionally, if the DTD connection is lost during an active session, the file-watching stream crashes, abruptly terminating the session.

Changelog Description:

Explain this cherry pick:

  • In one line that is accessible to most Flutter developers.
  • That describes the state prior to the fix.
  • That includes which platforms are impacted.
    See best practices for examples.

[flutter/187322] When DTD connection is lost or fails at startup during widget-preview on all platforms, the tool crashes with unhandled exceptions instead of exiting gracefully.

Workaround:

Is there a workaround for this issue?

Ensure that DTD is running and stable before starting widget-preview, and restart the tool if it crashes due to connection loss. There is no direct workaround to prevent the crash if the connection is lost.

Risk:

What is the risk level of this cherry-pick?

  • Low
  • Medium
  • High

Test Coverage:

Are you confident that your fix is well-tested by automated tests?

  • Yes
  • No

Validation Steps:

What are the steps to validate that this fix works?

  1. Startup Failure Validation:

    • Run flutter widget-preview start in a project where DTD is not available or is forced to fail.
    • Verify that the tool exits cleanly with the message: Failed to retrieve widget previews from the Dart Tooling Daemon (DTD). Ensure that the analysis server is running and reachable. (instead of crashing with a stack trace).
  2. Connection Loss Validation:

    • Run flutter widget-preview start and ensure it starts successfully.
    • Simulates DTD connection loss (e.g., by terminating the DTD process or the analysis server).
    • Verify that the tool logs a warning: Lost connection to the Dart Tooling Daemon (DTD). Live preview updates are paused. and does not crash the active session.

…lutter#186952)

Previously, unhandled RpcExceptions and connection-closed StateErrors
bubbled up and crashed the "flutter widget-preview start" command and
the active file-watching sync streams when the Dart Tooling Daemon (DTD)
connection was closed unexpectedly.

This change:
- Wraps startup DTD calls in a try-catch block and throws a
user-friendly ToolExit on failure instead of crashing.
- Gracefully catches DTD call exceptions inside the file-watcher stream
and logs a warning instead of crashing the active stream.
- Adds a unit test case in widget_preview_test.dart to verify that DTD
communication failures at startup result in a clean ToolExit.
@flutteractionsbot flutteractionsbot added the cp: review Cherry-picks in the review queue label May 29, 2026
@flutteractionsbot

Copy link
Copy Markdown
Contributor Author

@bkonyi please fill out the PR description above, afterwards the release team will review this request.

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 29, 2026
@flutter-dashboard

Copy link
Copy Markdown

This pull request was opened from and to a release candidate branch. This should only be done as part of the official Flutter release process. If you are attempting to make a regular contribution to the Flutter project, please close this PR and follow the instructions at Tree Hygiene for detailed instructions on contributing to Flutter.

Reviewers: Use caution before merging pull requests to release branches. Ensure the proper procedure has been followed.

@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label May 29, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces error handling when retrieving widget previews from the Dart Tooling Daemon (DTD) fails, catching Exception and StateError to either throw a ToolExit or log a warning, along with corresponding tests. Feedback suggests simplifying the duplicate catch blocks in widget_preview.dart by combining them and using type checks.

Comment thread packages/flutter_tools/lib/src/commands/widget_preview.dart

@justinmc justinmc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CPLGTM 👍

@justinmc justinmc added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 5, 2026
@auto-submit auto-submit Bot merged commit 853d854 into flutter:flutter-3.44-candidate.0 Jun 5, 2026
154 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD cp: review Cherry-picks in the review queue tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants