-
Notifications
You must be signed in to change notification settings - Fork 6k
Update "unregistered_view_type" error message #33450
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!). 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. |
test-exempt: improves error message This is an area where you could test it, e.g. by triggering the error and seeing if the message has the detail you want, but it's fine if you don't want to do that. |
@@ -140,7 +140,8 @@ | |||
NSObject<FlutterPlatformViewFactory>* factory = factories_[viewType].get(); | |||
if (factory == nil) { | |||
result([FlutterError errorWithCode:@"unregistered_view_type" | |||
message:@"trying to create a view with an unregistered type" | |||
message:@"trying to create a view with an unregistered type. Have " | |||
@"you called GeneratedPluginRegistrant.register?" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cyanglaz in the wild we saw this error fixed by calling GeneratedPluginRegistrant.register
flutter/flutter#100241 (comment) but perhaps there's also some -registerViewFactory:
to be done in the darwin case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I know it exists, the question is when this error happens is it reasonable to say "you need to call GeneratedPluginRegistrant.register
" because it's missing (add-to-app) or do they also need to call -registerViewFactory:
somewhere? We want this suggestion to actually be actionable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok.
The registerViewFactory:
is only meant to be called by the author of the PlatformView. If the user only uses a PlatformView plugin, they wouldn't be able to call registerViewFactory:
as they don't own the factory, so showing this to the app developer who uses the PlatformView plugin might cause confusion.
I think only include GeneratedPluginRegistrant.register
is fine for app developers.
We might be able to add some checks for the plugin/PlatformView authors to remind them to call registerViewFactory
in registerWithRegistrar
.
In addition to that, I think this part is also confusing: "trying to create a view with an unregistered type".
What view?(A view means lots of things, especially in add-to-app) Who or what tried to create a view? Maybe something like:
A UIKitView widget is trying to create a PlatformView with an unregistered type: <some type>.
If you are the author of the PlatformView, make sure `registerViewFactory` is invoked. See: https://docs.flutter.dev/development/platform-integration/platform-views?tab=ios-platform-views-objective-c-tab#on-the-platform-side-1 for more details.
If you are not the author of the PlatformView, make sure to call `GeneratedPluginRegistrant.register`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nits about whitespace and the URL
shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm
Outdated
Show resolved
Hide resolved
shell/platform/darwin/macos/framework/Source/FlutterPlatformViewController.mm
Outdated
Show resolved
Hide resolved
@@ -140,9 +140,9 @@ | |||
NSObject<FlutterPlatformViewFactory>* factory = factories_[viewType].get(); | |||
if (factory == nil) { | |||
result([FlutterError errorWithCode:@"unregistered_view_type" | |||
message:[NSString stringWithFormat:@"A UIKitView widget is trying to create a PlatformView with an unregistered type: < %@ >", viewType] | |||
message:[NSString stringWithFormat:@"A UIKitView widget is trying to create a PlatformView with an unregistered type: < %@ >", args[@"viewType"]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you pull args[@"viewType"]
into a local above std::string viewType([args[@"viewType"] UTF8String]);
and use it here to reduce the complexity of this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jmagman std::string viewType([args[@"viewType"] UTF8String]);
is already defined on line 132. The problem that I noticed by using only viewType
as variable was that the build failed with "error: cannot pass non-trivial object of type 'std::string'". So I guess it needs an NSString and not an std::String
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I think it should work if I use %s instead of %@
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use a %s
c string like that, there are encoding implications https://stackoverflow.com/a/60217425
I was suggesting
NSString* viewTypeString = args[@"viewType"];
std::string viewType(viewTypeString.UTF8String);
...
message:[NSString stringWithFormat:@"A UIKitView widget is trying to create a "
@"PlatformView with an unregistered type: < %@ >",
viewTypeString]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jmagman I added the NSString variable there. I was thinking that maybe I have to make it work using the existing variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more nit, then LGTM
shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm
Outdated
Show resolved
Hide resolved
message:[NSString stringWithFormat:@"A UIKitView widget is trying to create a " | ||
@"PlatformView with an unregistered type: < %@ >", | ||
viewTypeString] | ||
details:@"If you are the author of the PlatformView, make sure `registerViewFactory`" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you double check the spacing on these?
details:@"If you are the author of the PlatformView, make sure `registerViewFactory`" | |
details:@"If you are the author of the PlatformView, make sure `registerViewFactory` " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
message:[NSString stringWithFormat:@"A UIKitView widget is trying to create a " | ||
@"PlatformView with an unregistered type: < %@ >", | ||
viewType] | ||
details:@"If you are the author of the PlatformView, make sure `registerViewFactory`" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
details:@"If you are the author of the PlatformView, make sure `registerViewFactory`" | |
details:@"If you are the author of the PlatformView, make sure `registerViewFactory` " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
Fix for #100241
Updating the error message for
unregistered_view_type
to include a hint about a very common cause.Closes #100241
Pre-launch Checklist
writing and running engine tests.
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.