Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions packages/mix/lib/src/core/prop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,18 @@ class Prop<V> {
if (converted != null) {
mixValues.add(converted);
} else {
// Debug-only diagnostic to surface silent conversion failures
// Debug-only diagnostic to surface silent conversion failures while
// still returning the fallback resolved value.
assert(() {
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.

FlutterErrorDetails(
exception: FlutterError(
'Mix: could not convert value of type ${value.runtimeType} '
'to Mix<$V>. Register a MixConverter for <$V> or pass a Mix via Prop.mix.',
),
library: 'mix',
context: ErrorDescription('while resolving Prop<$V>'),
),
);

return true;
Expand Down
27 changes: 27 additions & 0 deletions packages/mix/test/src/core/prop_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,32 @@ void main() {
expect(resolved.right, 8.0); // from converted prop1
expect(resolved.bottom, 8.0); // from converted prop1
});

test(
'reports FlutterErrorDetails in debug mode and returns fallback value when merging an unconverted value with a Mix',
() {
final prop1 = Prop.value(10.0);
final prop2 = Prop.mix(MockMix<double>(20.0));
final merged = prop1.mergeProp(prop2);

FlutterErrorDetails? reported;
final previousOnError = FlutterError.onError;
FlutterError.onError = (details) {
reported = details;
};
addTearDown(() => FlutterError.onError = previousOnError);

final resolved = merged.resolveProp(MockBuildContext());

expect(resolved, 20.0);
expect(reported, isNotNull);
expect(
reported!.exceptionAsString(),
contains(
'Mix: could not convert value of type double to Mix<double>',
),
);
},
);
});
}
Loading