Hi chromium-mojo!
I'm trying to implement a
StructTraits template to ensure we do some custom mojom validation on a commonly passed mojom string. However, I'm hitting a compile-time error that is indicating a problem with how the mojom generation is occuring, but I'm not sure why. I saw a
previous post that mentioned this error, but I wasn't sure how to apply the suggestions to this change.
My impl is in
[Extensions] Create a mojom ExtensionId for message validation. and the error I'm getting is pasted below. Essentially it will allow us to serialize/deserialize from extensions::mojom::ExtensionId to
extensions::ExtensionId (a std::string) and automatically apply some custom validation (`crx_file::id_util::IdIsValid()`) so we don't have to do that in many different message receivers.
Would anyone be able to suggest any fixes to satisfy this error? Some thoughts and things I tried are:
- My interpretation of the error is that the generated mojom is not importing my new extension_id_mojom_traits.h/.cc StructTraits implementation, is that true? I followed the example of url_pattern_set_mojom_traits.h and it seems to be the same-ish...
- Is this because the right side of my StructTraits is a std::string (extensions::ExtensionId), which is too generic? I tried to create a custom struct instead of using extensions::ExtensionId, but got the same error...
- I tried including #include "mojo/public/cpp/bindings/string_traits_stl.h" so that the generated mojom knows how to deserialize std::string, but still got the same error.
Error:
- stderr:
- In file included from gen/extensions/common/mojom/frame.mojom.cc:12:
- In file included from gen/extensions/common/mojom/frame.mojom.h:20:
- In file included from ../../mojo/public/cpp/bindings/lib/serialization.h:20:
- In file included from ../../mojo/public/cpp/bindings/lib/array_serialization.h:23:
- In file included from ../../mojo/public/cpp/bindings/array_data_view.h:13:
- In file included from ../../mojo/public/cpp/bindings/lib/array_internal.h:30:
- In file included from ../../mojo/public/cpp/bindings/lib/validation_util.h:13:
- In file included from ../../mojo/public/cpp/bindings/lib/serialization_util.h:14:
- In file included from ../../mojo/public/cpp/bindings/lib/serialization_forward.h:20:
- ../../mojo/public/cpp/bindings/struct_traits.h:146:17: error: static assertion failed due to requirement 'internal::AlwaysFalse<std::string>::value': Cannot find the mojo::StructTraits specialization. Did you forget to include the corresponding header file?
- 146 | static_assert(internal::AlwaysFalse<T>::value,
- | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- gen/extensions/common/mojom/extension_id.mojom-shared.h:106:14: note: in instantiation of template class 'mojo::StructTraits<extensions::mojom::ExtensionIdDataView, std::string>' requested here
- 106 | decltype(Traits::id(input)) in_id = Traits::id(input);
- | ^
- ../../mojo/public/cpp/bindings/lib/serialization_forward.h:52:68: note: in instantiation of member function 'mojo::internal::Serializer<extensions::mojom::ExtensionIdDataView, const std::string>::Serialize' requested here
- 52 | Serializer<MojomType, std::remove_reference_t<InputUserType>>::Serialize(
- | ^
- gen/extensions/common/mojom/frame.mojom.cc:2262:19: note: in instantiation of function template specialization 'mojo::internal::Serialize<extensions::mojom::ExtensionIdDataView, const std::string &, mojo::internal::MessageFragment<extensions::mojom::internal::ExtensionId_Data> &>' requested here
- 2262 | mojo::internal::Serialize<::extensions::mojom::ExtensionIdDataView>(
- | ^
- 1 error generated.
Best regards,
Justin