Skip to content

fix(mix): report FlutterErrorDetails in debug mode when Prop value conversion fails - #1096

Merged
leoafarias merged 5 commits into
mainfrom
fix/prop-conversion-flutter-error
Oct 21, 2026
Merged

leoafarias merged 5 commits into
mainfrom
fix/prop-conversion-flutter-error

Conversation

@leoafarias

@leoafarias leoafarias commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Replaces the silent debugPrint('Mix: could not convert value of type ...') inside assert in Prop.resolveProp with FlutterError.reportError(FlutterErrorDetails(...)) so that failed Mix<V> conversions surface through Flutter's standard error pipeline (FlutterError.onError) in debug/test mode while still returning the fallback resolved value without crashing the widget build.

Root Cause & Motivation

When a Prop<V> accumulates both a Mix<V> source (e.g. a custom Mix<double> subclass passed via Prop.mix(...)) and a plain value source (ValueSource<V> or TokenSource<V> resolving to V), hasMixValues is true and Prop.resolveProp converts every non-Mix<V> entry via MixConverterRegistry.instance.tryConvert<V>(value).

Previously, when no MixConverter<V> was registered (such as for scalar double), Prop.resolveProp only called debugPrint inside an assert block and silently dropped the unconverted value. Because debugPrint does not route through FlutterError.onError, invalid Mix<V> + scalar V combinations went unnoticed in flutter test while printing console noise on every animation frame.

Using FlutterError.reportError(FlutterErrorDetails(...)) inside the assert(() { ... return true; }()) block follows Flutter's standard non-fatal error reporting pattern (like RenderFlex overflow):

  • Never crashes in production or debug: resolveProp continues and returns the resolved fallback value in both debug and release builds instead of throwing mid-build.
  • Zero overhead in release/profile builds: The assert block is stripped in release builds.
  • Fails flutter test automatically: TestWidgetsFlutterBinding hooks FlutterError.onError, so widget tests fail immediately (and tester.takeException() captures the FlutterError).

Release-mode behavior change

resolveProp also changes what release builds return when a source can't be converted. Previously the unconverted value was dropped and earlier Mix sources were merged, so Prop.mix(a).mergeProp(Prop.value(b)) resolved to a. Now an unconverted value replaces the Mix values collected before it, so the latest source wins, as everywhere else in Mix. A later Mix source still wins over it. The CHANGELOG records this under Bug fixes.

Verification

  • packages/mix/test/src/core/prop_test.dart covers both orders: a later Mix wins and the failure is reported (20.0), and a later unconverted value wins over an earlier Mix (30.0). The second test fails without the fix.
  • Full mix suite: 3,087 tests pass.
  • flutter test test/src/core/prop_test.dart
  • dart analyze lib/src/core/prop.dart test/src/core/prop_test.dart

@github-actions github-actions Bot added the mix label Oct 15, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T21:46:03.462849Z 67c5569 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@leoafarias leoafarias changed the title fix(mix): throw FlutterError in debug mode when Prop value conversion fails fix(mix): report FlutterErrorDetails in debug mode when Prop value conversion fails Oct 15, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a9c8f1ad49

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

debugPrint(
'Mix: could not convert value of type ${value.runtimeType} '
'to Mix<$V>. Register a MixConverter for <$V> or pass a Mix via Prop.mix.',
FlutterError.reportError(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Throw instead of only reporting conversion failures

When a converter is missing in a debug build, FlutterError.reportError invokes the global FlutterError.onError handler and then returns; it does not throw. Consequently, resolveProp still drops the unconverted value and returns the remaining Mix result, and a handler can swallow the error exactly as this new test does, so the intended fail-fast behavior is not implemented. Throw the FlutterError from the assertion block and test with throwsA if resolution is meant to abort.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Intentional: the first commit threw, and a9c8f1a switched to FlutterError.reportError so a missing converter is reported, like other recoverable framework errors (layout overflow), while the widget still renders the latest source. Reported errors reach FlutterError.onError, which fails widget tests. The CHANGELOG entry now records this and the release-mode fallback change.

Add an Unreleased CHANGELOG entry for the release-mode change (the latest
unconverted value now wins over earlier Mix sources) and the debug
reportError diagnostic, and split the test so each case asserts once.
@leoafarias
leoafarias merged commit 1c0a75f into main Oct 21, 2026
12 checks passed
@leoafarias
leoafarias deleted the fix/prop-conversion-flutter-error branch October 21, 2026 21:54
leoafarias added a commit that referenced this pull request Oct 21, 2026
Release mix 2.3.1: Prop conversion fallback and debug reporting (#1096).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant