Skip to content

Conversation

@bkonyi
Copy link
Contributor

@bkonyi bkonyi commented Oct 23, 2025

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: #81666

…ack traces

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: #81666
@github-actions github-actions bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Oct 23, 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 transformWithCallSite extension method on Stream to provide more useful stack traces when errors occur within stream transformers. This is achieved by capturing the stack trace at the call site and reporting it on error. The new method is then applied across the codebase in various places where stream transformations happen.

The implementation is solid, but I have one suggestion to improve it further by chaining the original stack trace with the call site trace, instead of replacing it. This will provide even more context for debugging, showing both where the error originated and where the transform was called.

Comment on lines 601 to 602
// Report the error with the call site trace.
controller.addError(e, callSiteTrace);
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This implementation replaces the original stack trace with the call site trace. While this adds the desired context of where transformWithCallSite was called, it loses the valuable information from the original stack trace, which shows where the error occurred within the transformer. A better approach would be to chain the stack traces to provide both contexts.

You can use Chain from the stack_trace package to combine them. This will make debugging easier as both the call site and the error location will be available.

Note that this change will require updating the corresponding test in packages/flutter_tools/test/general.shard/utils_test.dart to inspect the Chain object.

          // Report the error with the call site trace chained with the original trace.
          controller.addError(e, Chain([Trace.from(s), callSiteTrace]));

@bkonyi bkonyi requested review from a team as code owners October 24, 2025 16:24
@github-actions github-actions bot added platform-ios iOS applications specifically a: desktop Running on desktop team-android Owned by Android platform team team-ios Owned by iOS platform team labels Oct 24, 2025
@bkonyi bkonyi requested a review from jyameo October 24, 2025 17:32
Copy link
Contributor

@jyameo jyameo left a comment

Choose a reason for hiding this comment

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

lgtm!

@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 27, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Oct 27, 2025
Merged via the queue into master with commit 860e807 Oct 27, 2025
152 checks passed
@auto-submit auto-submit bot deleted the improve_stream_transformation_errors branch October 27, 2025 16:32
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 28, 2025
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Oct 28, 2025
flutter/flutter@4c91098...7cf0dc1

2025-10-28 [email protected] Roll Skia from 602bbd4af8f9 to e4d3d8f31aef (4 revisions) (flutter/flutter#177647)
2025-10-28 [email protected] Fix AppBar Semantics namesRoute for mismatched platforms (flutter/flutter#176694)
2025-10-28 [email protected] Fix Popup menu Semantics label for mismatched platforms (flutter/flutter#177049)
2025-10-28 [email protected] Roll Skia from 8b2d056701df to 602bbd4af8f9 (1 revision) (flutter/flutter#177628)
2025-10-28 [email protected] Roll Skia from 5723f87f8530 to 8b2d056701df (3 revisions) (flutter/flutter#177626)
2025-10-27 [email protected] Roll Skia from 170c11f1ddc5 to 5723f87f8530 (6 revisions) (flutter/flutter#177618)
2025-10-27 [email protected] Enhance DropdownMenuEntry's labelWidget docs (flutter/flutter#177160)
2025-10-27 [email protected] Regenerated lockfiles for New Template Values (flutter/flutter#177617)
2025-10-27 [email protected] Correct editable text and placeholder position in baseline aligned stack (flutter/flutter#177342)
2025-10-27 49699333+dependabot[bot]@users.noreply.github.com Bump actions/upload-artifact from 4 to 5 in the all-github-actions group (flutter/flutter#177620)
2025-10-27 [email protected] add gn flag to optimize builds for size (flutter/flutter#176835)
2025-10-27 [email protected] disable metal for crosscompile from mac to linux (flutter/flutter#176639)
2025-10-27 [email protected] [DDM] enable host builds in the merge queue (flutter/flutter#177446)
2025-10-27 [email protected] Disable vulkan X11 support when building for minimal linux (flutter/flutter#176697)
2025-10-27 [email protected] Roll Skia from 77348c40d101 to 170c11f1ddc5 (6 revisions) (flutter/flutter#177602)
2025-10-27 [email protected] Set the font weight variation axis based on the text style's FontWeight (flutter/flutter#175771)
2025-10-27 [email protected] Fixed `RuntimeEffect` with `ImageFilter.compose` (flutter/flutter#177510)
2025-10-27 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Clean before building when framework headers change (#177512)" (flutter/flutter#177610)
2025-10-27 [email protected] [skia] Disable legacy png encoding/decoding in skp (flutter/flutter#177462)
2025-10-27 [email protected] Clean before building when framework headers change (flutter/flutter#177512)
2025-10-27 [email protected] Roll dartdoc to 9.0.0 (flutter/flutter#177590)
2025-10-27 [email protected] Fix typo in comment about `manifestFile` in `DeepLinkJsonFromManifestTaskHelper.kt‎` (flutter/flutter#177538)
2025-10-27 [email protected] Fix RoundedSuperellipse crashes for tiny corners (flutter/flutter#177070)
2025-10-27 [email protected] Roll Packages from 53d6138 to bbf96a0 (7 revisions) (flutter/flutter#177588)
2025-10-27 [email protected] Fix missing list indicators in CHANGELOG.md (flutter/flutter#177484)
2025-10-27 [email protected] [ Tool ] Add `Stream.transformWithCallSite` to provide more useful stack traces (flutter/flutter#177470)
2025-10-27 [email protected] Roll Skia from 06243224ecf0 to 77348c40d101 (1 revision) (flutter/flutter#177585)
2025-10-27 [email protected] Add guided error for precompiled cache error (flutter/flutter#177327)
2025-10-27 [email protected] Roll Fuchsia Linux SDK from tKrvmvTOQITL81oOC... to ir6J2isKAYa1jNLyJ... (flutter/flutter#177578)
2025-10-27 [email protected] Roll Skia from 784ed1787bd6 to 06243224ecf0 (1 revision) (flutter/flutter#177575)
2025-10-27 [email protected] Roll Skia from de52b3a7585a to 784ed1787bd6 (5 revisions) (flutter/flutter#177571)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter-zl pushed a commit that referenced this pull request Oct 31, 2025
…ack traces (#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: #81666
@bkonyi bkonyi added the cp: beta cherry pick this pull request to beta release candidate branch label Nov 4, 2025
flutteractionsbot pushed a commit to flutteractionsbot/flutter that referenced this pull request Nov 4, 2025
…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
bkonyi added a commit that referenced this pull request Nov 7, 2025
This was incorrectly updated as part of #177470
github-merge-queue bot pushed a commit that referenced this pull request Nov 7, 2025
bkonyi added a commit that referenced this pull request Nov 7, 2025
IvoneDjaja pushed a commit to IvoneDjaja/flutter that referenced this pull request Nov 22, 2025
reidbaker pushed a commit to AbdeMohlbi/flutter that referenced this pull request Dec 10, 2025
…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
reidbaker pushed a commit to AbdeMohlbi/flutter that referenced this pull request Dec 10, 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 cp: beta cherry pick this pull request to beta release candidate branch 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.

2 participants