Skip to content

Clean up avoid_type_to_string suppressions#186869

Merged
auto-submit[bot] merged 1 commit into
flutter:masterfrom
mvincentong:fix-avoid-type-to-string-lints
Jun 2, 2026
Merged

Clean up avoid_type_to_string suppressions#186869
auto-submit[bot] merged 1 commit into
flutter:masterfrom
mvincentong:fix-avoid-type-to-string-lints

Conversation

@mvincentong
Copy link
Copy Markdown
Contributor

@mvincentong mvincentong commented May 21, 2026

Fixes #185310.

Issue: Several avoid_type_to_string suppressions were either avoidable or undocumented. The Flutter tool crash analytics path still needs a best-effort concrete exception category for unknown error types, so replacing the type with a generic category loses useful crash signal.

Fix:

  • Keeps tool crash analytics on error.runtimeType.toString() with a local comment explaining why that suppression is intentional.
  • Makes PreparePackageException and UnpublishException final and uses $PreparePackageException / $UnpublishException so their string output follows future class renames.
  • Leaves GitHub crash template sanitization on stable categories where privacy/sanitization matters.
  • Adds focused coverage for the bot exception toString() output.

Tests:

  • ./bin/dart format --output=none --set-exit-if-changed packages/flutter_tools/lib/runner.dart packages/flutter_tools/test/general.shard/runner/runner_test.dart
  • ./bin/flutter analyze dev/bots/prepare_package/common.dart dev/bots/unpublish_package.dart packages/flutter_tools/lib/runner.dart packages/flutter_tools/lib/src/reporting/github_template.dart dev/bots/test/prepare_package_test.dart dev/bots/test/unpublish_package_test.dart packages/flutter_tools/test/general.shard/runner/runner_test.dart packages/flutter_tools/test/general.shard/github_template_test.dart
  • ./bin/flutter test packages/flutter_tools/test/general.shard/runner/runner_test.dart packages/flutter_tools/test/general.shard/github_template_test.dart
  • ./bin/flutter test packages/flutter_tools/test/general.shard/github_template_test.dart
  • ./bin/dart test dev/bots/test/prepare_package_test.dart
  • ./bin/dart test dev/bots/test/unpublish_package_test.dart
  • git diff --check

Risk: Low. The PR removes avoidable suppressions, keeps the one remaining suppression explicit, and preserves useful crash analytics signal where the tool is not obfuscated.

@flutter-dashboard
Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label May 21, 2026
@mvincentong mvincentong force-pushed the fix-avoid-type-to-string-lints branch from 78780ab to 790e522 Compare May 21, 2026 10:45
Copy link
Copy Markdown
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 replaces runtimeType.toString() calls with hardcoded strings or string interpolation to address the avoid_type_to_string lint. Feedback indicates that hardcoding class names results in a loss of dynamic behavior for subclasses. Furthermore, using string interpolation on Type objects may not effectively resolve the lint's underlying concerns regarding obfuscation and could still be flagged by the linter.

Comment thread dev/bots/prepare_package/common.dart Outdated
Comment thread dev/bots/unpublish_package.dart Outdated
Comment thread packages/flutter_tools/lib/runner.dart Outdated
Comment thread packages/flutter_tools/lib/src/reporting/github_template.dart Outdated
@mvincentong mvincentong force-pushed the fix-avoid-type-to-string-lints branch from 790e522 to 9ef677d Compare May 21, 2026 10:50
@mvincentong
Copy link
Copy Markdown
Contributor Author

Addressed Gemini feedback in head 9ef677d4a0: the tool crash paths now use explicit stable exception category names instead of interpolating runtimeType, and PreparePackageException / UnpublishException are final before using explicit class names in toString().

Comment thread dev/bots/prepare_package/common.dart Outdated
Comment thread packages/flutter_tools/lib/runner.dart Outdated
@mvincentong mvincentong force-pushed the fix-avoid-type-to-string-lints branch from 9ef677d to 607ee2b Compare May 29, 2026 13:19
@mvincentong mvincentong changed the title Remove avoid_type_to_string suppressions Clean up avoid_type_to_string suppressions May 29, 2026
@mvincentong
Copy link
Copy Markdown
Contributor Author

Addressed the review feedback in 607ee2b. The bot exceptions now use $PreparePackageException / $UnpublishException, and _errorTypeName keeps the unknown-error runtimeType fallback with a local avoid_type_to_string comment explaining why Object is too lossy there. Verification rerun: formatter, targeted analyze, runner_test.dart, prepare_package_test.dart, unpublish_package_test.dart, and git diff --check all pass.

Copy link
Copy Markdown
Contributor

@bkonyi bkonyi left a comment

Choose a reason for hiding this comment

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

Almost there!

Comment thread packages/flutter_tools/lib/runner.dart Outdated
@bkonyi bkonyi added the CICD Run CI/CD label May 29, 2026
@mvincentong mvincentong force-pushed the fix-avoid-type-to-string-lints branch from 607ee2b to 4fc4d62 Compare May 30, 2026 14:27
@github-actions github-actions Bot removed the CICD Run CI/CD label May 30, 2026
@mvincentong
Copy link
Copy Markdown
Contributor Author

Updated in 4fc4d62 to match the maintainer feedback: the tool crash analytics path now keeps error.runtimeType.toString() with a local suppression comment, and the _errorTypeName mapping helper is removed so unknown crash types are not collapsed. The bot exceptions still use $PreparePackageException / $UnpublishException with focused tests. Verification rerun: targeted analyze, runner/github_template tests, bot exception tests, formatter check, and git diff --check.

@bkonyi bkonyi added the CICD Run CI/CD label Jun 1, 2026
Copy link
Copy Markdown
Contributor

@bkonyi bkonyi left a comment

Choose a reason for hiding this comment

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

One last change, then this LGTM!

Comment thread packages/flutter_tools/lib/src/reporting/github_template.dart Outdated
@mvincentong mvincentong force-pushed the fix-avoid-type-to-string-lints branch from 4fc4d62 to 29c127e Compare June 1, 2026 17:52
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 1, 2026
@mvincentong
Copy link
Copy Markdown
Contributor Author

Addressed the last review thread in 29c127e: sanitizedCrashException now keeps runtimeType.toString() for unknown crash objects so generated GitHub issues preserve the concrete error type, with focused coverage for a custom exception. Verification rerun: ../../bin/dart test test/general.shard/github_template_test.dart, ./bin/flutter analyze packages/flutter_tools/lib/src/reporting/github_template.dart packages/flutter_tools/test/general.shard/github_template_test.dart, ./bin/dart format --output=none --set-exit-if-changed packages/flutter_tools/lib/src/reporting/github_template.dart packages/flutter_tools/test/general.shard/github_template_test.dart, and git diff --check.

bkonyi
bkonyi previously approved these changes Jun 1, 2026
@bkonyi bkonyi requested a review from chingjun June 1, 2026 18:47
@bkonyi bkonyi added the CICD Run CI/CD label Jun 1, 2026
Comment thread dev/bots/prepare_package/common.dart Outdated
Comment thread dev/bots/unpublish_package.dart Outdated
@mvincentong mvincentong force-pushed the fix-avoid-type-to-string-lints branch from 29c127e to ddab037 Compare June 2, 2026 04:03
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 2, 2026
@mvincentong
Copy link
Copy Markdown
Contributor Author

Addressed the two output-initialization nits in ddab037: both bot exception toString implementations now initialize output as $PreparePackageException: $message / $UnpublishException: $message and keep the existing stderr append behavior. Verification rerun: ./bin/dart format --output=none --set-exit-if-changed dev/bots/prepare_package/common.dart dev/bots/unpublish_package.dart, ./bin/dart test dev/bots/test/prepare_package_test.dart, ./bin/dart test dev/bots/test/unpublish_package_test.dart, ./bin/flutter analyze dev/bots/prepare_package/common.dart dev/bots/unpublish_package.dart dev/bots/test/prepare_package_test.dart dev/bots/test/unpublish_package_test.dart, and git diff --check.

@chingjun chingjun added the CICD Run CI/CD label Jun 2, 2026
@chingjun chingjun added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 2, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue Jun 2, 2026
Merged via the queue into flutter:master with commit c1bd1ef Jun 2, 2026
174 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 2, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Jun 3, 2026
…11832)

Manual roll requested by tarrinneal@google.com

flutter/flutter@701665b...2ba5420

2026-06-03 engine-flutter-autoroll@skia.org Roll Packages from 818b310 to b11504f (8 revisions) (flutter/flutter#187511)
2026-06-03 mdebbar@google.com Add new file patterns for team-web labeler (flutter/flutter#187397)
2026-06-03 engine-flutter-autoroll@skia.org Roll Skia from 279b17fe9fc1 to d625048c853a (12 revisions) (flutter/flutter#187483)
2026-06-03 chris@bracken.jp [SwiftPM] Fix prefer_initializing_formals lint (flutter/flutter#187502)
2026-06-03 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from q27k7_um1GvVrySZS... to ap7MhLX4TdpWRrLS_... (flutter/flutter#187478)
2026-06-03 bkonyi@google.com [SwiftPM] Fix concurrent directory/file/symlink creation crashes (flutter/flutter#186953)
2026-06-03 flar@google.com [Impeller] Fix positioning of text shadow masks (flutter/flutter#187460)
2026-06-02 burak.karahan@mail.ru Remove Material imports from painting tests (flutter/flutter#186937)
2026-06-02 awolff@google.com Add android_hardware_smoke_test integration tests (flutter/flutter#187130)
2026-06-02 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#187471)
2026-06-02 pq@users.noreply.github.com [flutter tool] propagate analytics env to sub-tools (flutter/flutter#186780)
2026-06-02 30870216+gaaclarke@users.noreply.github.com Adds macro for fragment shaders to support flutter <= 3.44 (flutter/flutter#187316)
2026-06-02 116356835+AbdeMohlbi@users.noreply.github.com Small clean-up in different java files under `engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/` (flutter/flutter#186631)
2026-06-02 1961493+harryterkelsen@users.noreply.github.com refactor(web): Unify ui.Path code for CanvasKit and Skwasm (flutter/flutter#187331)
2026-06-02 engine-flutter-autoroll@skia.org Roll Packages from f5d50ca to 818b310 (2 revisions) (flutter/flutter#187441)
2026-06-02 faheemabbas766@gmail.com Allow selecting multi-digit device options (flutter/flutter#186184)
2026-06-02 puneetkukreja98@gmail.com Improve error message for type mismatch in Navigator.pop and maybePop. (flutter/flutter#186571)
2026-06-02 sanaullah.383@hotmail.com Remove semantics_tester import from material_button_test.dart (flutter/flutter#184807)
2026-06-02 bkonyi@google.com [flutter_tools] Refactor hostPlatform to use Abi.current() (flutter/flutter#185369)
2026-06-02 mvincentong@gmail.com Clean up avoid_type_to_string suppressions (flutter/flutter#186869)
2026-06-02 202459002+Lukes-Lair@users.noreply.github.com Update Flutter documentation links in flutter_console.bat (flutter/flutter#187354)
2026-06-02 154381524+flutteractionsbot@users.noreply.github.com Revert "[Impeller] Allow attaching specific texture mip levels and slices" (flutter/flutter#187445)

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 stuartmorgan@google.com,tarrinneal@google.com 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate ignored avoid_type_to_string lints

3 participants