Repository navigation
[tool][web] Intercept dart2wasm errors & append JS migration footers - #190476
Conversation
When compiling a web project with `--wasm` (or running a dry-run) that encounters incompatible legacy JS interop dependencies (`dart:html` or `package:js`), standard `--wasm` builds default to an uncaught `ProcessException` dumping an internal stack trace, while dry-runs lack actionable migration remediation. This change: * Invokes `ProcessUtils.run(throwOnError: false)` in `Dart2WasmTarget.build` to forward uncorrupted compiler stdout/stderr directly to the logger without throwing an unformatted `ProcessException`. * Adds `kWasmErrorsMoreInfo` constant targeting https://flutter.dev/to/wasm-errors. * Inspects standard compile failure and Wasm dry-run outputs for instances of `dart:html` or `package:js`, appending an educational migration footer when matched. * Terminates fatal Wasm builds cleanly via `throwToolExit`, preventing internal tool stack trace spillage. Fixes flutter#190466
There was a problem hiding this comment.
Code Review
This pull request adds checks for legacy web imports (dart:html and package:js) during WebAssembly compilation, printing a migration warning with diagnostic guidance if they are detected. Corresponding tests were added to verify this behavior. The review feedback suggests refactoring the duplicated check and warning logic into a private helper method to improve maintainability.
Addresses Gemini Code Assist review comments and Tree_analyze lint failures: * Extracts _checkForLegacyWebImports helper method on Dart2WasmTarget to reuse across regular Wasm builds and dry-runs. * Removes redundant throwOnError: false parameter on ProcessUtils.run. * Fixes obvious local variable type annotations, import ordering, string concatenation, and bare catch clauses in web target tests.
Replaces substring checks with structured pattern matching across the complete set of legacy web APIs: * Defines kLegacyWebLibraries covering dart:html, dart:indexed_db, dart:js, dart:js_util, dart:svg, dart:web_audio, dart:web_gl, dart:web_sql, and package:js. * Replaces naive substring checks with _kLegacyImportErrorPattern matching exact Dart CFE and dart2wasm diagnostic syntax. * Eliminates false positives from incidental occurrences of legacy library names in unrelated build failures or filenames. * Adds exhaustive positive and negative unit test coverage across standard Wasm builds and dry runs. Fixes flutter#190466
| const kWasmMoreInfo = 'See https://flutter.dev/to/wasm for more information.'; | ||
| const String kWasmMoreInfo = 'See https://flutter.dev/to/wasm for more information.'; | ||
| const String kWasmErrorsMoreInfo = | ||
| 'See https://flutter.dev/to/wasm-errors for diagnostic and migration guidance.'; |
There was a problem hiding this comment.
go link defined in flutter/website#13662
| ); | ||
| } | ||
|
|
||
| static final RegExp _kLegacyImportErrorPattern = RegExp( |
There was a problem hiding this comment.
The text here seems to be load-bearing (if it changes, this will break), I'm guessing there's no other way to do this?
| 'dart:svg', | ||
| 'dart:web_audio', | ||
| 'dart:web_gl', | ||
| 'dart:web_sql', |
There was a problem hiding this comment.
nit: web_sql no longer exists in the shipped SDK.
| _kLegacyImportErrorPattern.hasMatch(stderr)) { | ||
| environment.logger.printStatus( | ||
| 'Note: WebAssembly compilation failed due to legacy web imports.\n' | ||
| 'Migrate your project from dart:html and package:js to package:web and dart:js_interop.\n' |
There was a problem hiding this comment.
nit: Maybe deprecated interop libraries to supported interop libraries instead.
…lutter#190591) Relands flutter#190475 (reverted in flutter#190583 due to a semantic collision with flutter#190476). When compiling web targets (dart2js and dart2wasm) or running dry runs with the record-use feature flag enabled, flutter_tools explicitly passed --enable-experiment=record-use to the compiler. Since record-use is enabled by default in recent Dart SDKs, passing this flag caused warning spam during standard compilation and dry runs. * Remove --enable-experiment=record-use from Dart2JSTarget and Dart2WasmTarget in web.dart. * Remove expected flag from test commands in web_test.dart and web_dry_run_test.dart, including the recently added occurrence in addWasmCompilerErrorCommand from flutter#190476 that caused the post-commit test failure. Fixes flutter#190465
…12420) Manual roll requested by [email protected] flutter/flutter@b766512...27b0988 2026-08-05 [email protected] reland(tool): remove redundant --enable-experiment=record-use flag (flutter/flutter#190591) 2026-08-05 [email protected] Windows: Propagate enabled accessibility state (flutter/flutter#190507) 2026-08-05 [email protected] Roll Fuchsia Test Scripts from ltbuIH9Z3T_yOuigu... to vcANVO8VIDQHasH1X... (flutter/flutter#190589) 2026-08-05 [email protected] Document frozen embedder API structs (flutter/flutter#186842) 2026-08-05 [email protected] Document super call order for State.didChangeDependencies (flutter/flutter#185945) 2026-08-05 [email protected] Move examples of `flutter/widgets` widgets out from `flutter/material` (flutter/flutter#189532) 2026-08-05 [email protected] [web] Use thread local strike caches in skwasm (flutter/flutter#190048) 2026-08-05 [email protected] doc: fix typo in see also section for PrimaryScrollController.maybeOf (flutter/flutter#190386) 2026-08-05 [email protected] Migrate the shell unit tests from legacy Dart native functions to FFI (flutter/flutter#190473) 2026-08-05 [email protected] render proxy box now defaults baseline calculation to null (flutter/flutter#190269) 2026-08-05 [email protected] Update Widgets Localizations from Translation Console (flutter/flutter#190503) 2026-08-04 [email protected] Revert: fix(tool): remove redundant --enable-experiment=record-use flag (flutter/flutter#190583) 2026-08-04 [email protected] Roll Fuchsia Test Scripts from 1frGe_KltAJKkeyPg... to ltbuIH9Z3T_yOuigu... (flutter/flutter#190561) 2026-08-04 [email protected] iOS,macOS: add tsan and ubsan support for Swift (flutter/flutter#190497) 2026-08-04 [email protected] fix: update on_message_ to nullptr after window destroy so that dart gets destroy message (flutter/flutter#185807) 2026-08-04 [email protected] [flutter_tools] Gracefully handle locked Windows files during clean (flutter/flutter#190095) 2026-08-04 [email protected] iOS,macOS: make Logger thread-safe, conform to Sendable (flutter/flutter#190488) 2026-08-04 [email protected] iOS: Eliminate use of IOSContextNoop in platform view tests (reland) (flutter/flutter#190509) 2026-08-04 [email protected] fix(tool): remove redundant --enable-experiment=record-use flag (flutter/flutter#190475) 2026-08-04 [email protected] android_hardware_smoke_test: Detect blank image failures or EGL initialization warnings and retry (flutter/flutter#190110) 2026-08-04 [email protected] Bumps text gamma on windows to match skia. (flutter/flutter#190477) 2026-08-04 [email protected] Roll Skia from 48b58ee222f1 to a8583a0a2c11 (2 revisions) (flutter/flutter#190537) 2026-08-04 [email protected] [tool][web] Intercept dart2wasm errors & append JS migration footers (flutter/flutter#190476) 2026-08-04 [email protected] [record_use] Migrate IconTreeShaker to `package:record_use` (flutter/flutter#190225) 2026-08-04 [email protected] Handle unexpected exceptions during Azure metadata detection (flutter/flutter#189457) 2026-08-04 [email protected] Fix merge conflict from flutter/flutter#190369 (flutter/flutter#190544) 2026-08-04 [email protected] Prepare device support symbols (flutter/flutter#190369) 2026-08-04 [email protected] Roll Packages from ac87e65 to 3498b9d (1 revision) (flutter/flutter#190532) 2026-08-04 [email protected] Roll Skia from a08d918ebd6a to 48b58ee222f1 (11 revisions) (flutter/flutter#190527) 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
When compiling a web project with
--wasm(or running a dry-run) that encounters incompatible legacy JS interop dependencies (dart:htmlorpackage:js), standard--wasmbuilds default to an uncaughtProcessExceptiondumping an internal stack trace, while dry-runs lack actionable migration remediation.This change:
ProcessUtils.run(throwOnError: false)inDart2WasmTarget.buildto forward uncorrupted compiler stdout/stderr directly to the logger without throwing an unformattedProcessException.kWasmErrorsMoreInfoconstant targeting https://flutter.dev/to/wasm-errors.dart:htmlorpackage:js, appending an educational migration footer when matched.throwToolExit, preventing internal tool stack trace spillage.Fixes #190466