[CP-stable][Tool] Handle DTD connection failures gracefully in widget-preview#187323
Conversation
…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.
|
@bkonyi please fill out the PR description above, afterwards the release team will review this request. |
|
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. |
There was a problem hiding this comment.
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.
853d854
into
flutter:flutter-3.44-candidate.0
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 unhandledRpcExceptionorStateErrorshowing 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:
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?
Test Coverage:
Are you confident that your fix is well-tested by automated tests?
Validation Steps:
What are the steps to validate that this fix works?
Startup Failure Validation:
flutter widget-preview startin a project where DTD is not available or is forced to fail.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).Connection Loss Validation:
flutter widget-preview startand ensure it starts successfully.Lost connection to the Dart Tooling Daemon (DTD). Live preview updates are paused.and does not crash the active session.