-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minor error message improvement: record positional fields #42
Comments
Hey @marcglasberg, great feedback on the error messages. I like the model you're describing of what/why/how to fix 👍 Positional record fields can be serialized as you describe, and this is how We also felt that using named parameters required a minimal amount of additional code Please let me know if we are being too opinionated here, though, and if the use of positional record fields would improve your experience. |
I think your argument about being accessible and debuggable makes perfect sense, and I'm happy with it. But it's not always that we have control over the types we use. Obligatory named params means you won't allow third-party types that use positional parameters. Which may force me to convert to/from the internal third-party classes and my own classes that I can send over to Celest. Or maybe actually it won't force me to do that! I just need to override the toJson/fromJson with your new extended types override feature, right? |
Yes! I think the solution to this is overrides which can define a custom So given the following type: // Defined in another package
class BadType {
const BadType(this.positionalFields);
final (String a, String b) positionalFields;
} You could have an override like the following: @override
extension type FixBadType(BadType it) implements BadType {
factory FixBadType.fromJson(Map<String, Object?> json) {
final positionalFields = json['positionalFields'] as Map<String, Object?>;
return BadType(
(positionalFields['a'] as String, positionalFields['b'] as String),
) as FixBadType;
}
Map<String, Object?> toJson() {
return {
'positionalFields': {
'a': positionalFields.$1,
'b': positionalFields.$2,
},
};
}
} I will close this for now, but feel free to reopen in the future if custom overrides don't fully solve the problem! |
@dnys1 maybe please still leave it open? We went on a tangent, but the issue was just about a minor improvement in the error message, by applying the What/Why/How format. |
Whoops! Yes, we can |
Currently, I'm getting this error message:
Very minor, but maybe the error messages could follow the format in this order:
What. Why (when applicable). How to fix it
.Currently you have
Why. What
and noHow
.In
What/Why/How
format it becomes:A question: Do you feel that anything that doesn't have very "natural" JSON representation should not be allowed? Because technically it is serializable with
$1
and$2
just like Dart does:Or even:
Do you feel this may create problems?
The text was updated successfully, but these errors were encountered: