Mojom compiler: Improves error message by giving misspelled identifier.
Instead of printing a meaningless Python object ID and a cryptic Python error print "unrecognized kind" and the type-spec for the unrecognized kind.
This came up for me when I was writing a longer .mojom file and I had misspelled the name of one of my structs when I was attempting to include the struct in a union. The compiler told me something was wrong but I had no idea which identifier I had misspelled.
R=azani@chromium.org
Review URL: https://codereview.chromium.org/1294043002 .
diff --git a/mojo/public/tools/bindings/generators/mojom_cpp_generator.py b/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
index 3d59087..160f657 100644
--- a/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
+++ b/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
@@ -146,7 +146,13 @@
return "mojo::ScopedMessagePipeHandle"
if mojom.IsSharedBufferKind(kind):
return "mojo::ScopedSharedBufferHandle"
- return _kind_to_cpp_type[kind]
+ # TODO(rudominer) After improvements to compiler front end have landed,
+ # revisit strategy used below for emitting a useful error message when an
+ # undefined identifier is referenced.
+ val = _kind_to_cpp_type.get(kind)
+ if (val is not None):
+ return val
+ raise Exception("Unrecognized kind %s" % kind.spec)
def GetCppWrapperType(kind):
if mojom.IsEnumKind(kind):