Skip to content

Conversation

@flutteractionsbot
Copy link

@flutteractionsbot flutteractionsbot commented Nov 4, 2025

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?

Example issue: #81666

Changelog Description:

Explain this cherry pick in one line that is accessible to most Flutter developers. See best practices for examples

Improve logging for UTF-8 decoding errors.

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 production app (the app crashes on launch)

When an exception is thrown within a transformer provided to Stream.transform(...), an asynchronous stack trace pointing to the internal transformation machinery is reported instead of where the call to transform(...) was made, making tracking down where these exceptions come from extremely difficult.

Workaround:

Is there a workaround for this issue?

No.

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?

Not a fix, just additional logging. Tests have been added to ensure this extension works as expected.

…ack traces (flutter#177470)

Exceptions thrown within a stream transformer don't provide any context
as to where the call to `transform(...)` occurred within the program,
often resulting in stack traces consisting of only Dart SDK sources.

This change adds a new extension method on `Stream` called
`transformWithCallSite`, which captures the current `StackTrace` upon
invocation. This stack trace is reported in the case of an error in
order to provide context for better error reporting.

Example issue: flutter#81666
@flutteractionsbot flutteractionsbot requested review from a team as code owners November 4, 2025 16:15
@flutter-dashboard
Copy link

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.

@flutteractionsbot flutteractionsbot added the cp: review Cherry-picks in the review queue label Nov 4, 2025
@flutteractionsbot
Copy link
Author

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

@github-actions github-actions bot added platform-ios iOS applications specifically tool Affects the "flutter" command-line tool. See also t: labels. a: desktop Running on desktop team-android Owned by Android platform team team-ios Owned by iOS platform team labels Nov 4, 2025
Copy link
Contributor

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

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 a Stream.transformWithCallSite extension method and a utf8LineDecoder utility to provide more useful stack traces when stream transformations fail. These changes are propagated throughout the flutter_tools codebase, improving debuggability. A new test is also added to verify the behavior of transformWithCallSite. The changes are generally good, but I've found one critical issue where the new utf8LineDecoder is used incorrectly, potentially causing issues with decoding adb logcat output.

.transform<String>(decoder)
.transform<String>(const LineSplitter())
.listen(_onLine);
_adbProcess.stdout.transform(utf8LineDecoder).listen(_onLine);
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The stdout stream from adb logcat can contain invalid UTF-8, as noted in the comment on line 1119. Using utf8LineDecoder here is incorrect because it does not ignore decoding errors, which could lead to lost log output or crashes. You should apply transformWithCallSite manually with the existing decoder that has reportErrors: false, similar to how stderr is handled in this same block.

Suggested change
_adbProcess.stdout.transform(utf8LineDecoder).listen(_onLine);
_adbProcess.stdout.transformWithCallSite(decoder).transform(const LineSplitter()).listen(_onLine);

Copy link
Contributor

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

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 a Stream.transformWithCallSite extension method to provide more useful stack traces when stream transformations fail. It also adds a utf8LineDecoder stream transformer that combines UTF-8 decoding with line splitting, leveraging the new extension method. These changes have been applied across the codebase, replacing direct calls to utf8.decoder and LineSplitter with the new, more robust, and cleaner utilities. This is a solid improvement for debuggability and code maintainability. I have one suggestion for consistency.

Copy link
Contributor

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

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 a Stream.transformWithCallSite extension method to provide more useful stack traces for stream errors, and a utf8LineDecoder utility for convenience. The changes refactor numerous parts of the codebase to use these new utilities, which should improve debuggability.

However, I've found a critical regression in packages/flutter_tools/lib/src/android/android_device.dart. The refactoring to use utf8LineDecoder for stdout from logcat incorrectly uses a UTF-8 decoder that does not handle malformed input. This could cause the tool to crash when processing logcat output, undoing a previous bug fix. The rest of the refactoring appears correct and beneficial.

@hellohuanlin hellohuanlin requested review from bkonyi and jyameo November 6, 2025 22:28
Copy link
Contributor

@camsim99 camsim99 left a comment

Choose a reason for hiding this comment

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

LGTM

@camsim99 camsim99 added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 11, 2025
@auto-submit auto-submit bot merged commit 5205556 into flutter:flutter-3.38-candidate.0 Nov 11, 2025
146 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop autosubmit Merge PR when tree becomes green via auto submit App cp: review Cherry-picks in the review queue platform-ios iOS applications specifically team-android Owned by Android platform team team-ios Owned by iOS platform team 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