New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 788704 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Last visit > 30 days ago
Closed: Dec 2017
Cc:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

[Mojo] Using any symbol in mojom without importing required file gives cryptic error

Project Member Reported by blundell@chromium.org, Nov 27 2017

Issue description

A colleague of mine discovered this behavior:

If you use a typemapped type Foo in a mojom file but inadvertently forget to import the mojom file in which Foo is defined, you end up with a very cryptic error (that makes it not-at-all obvious what the source of the problem is). A simple repro case (the missing import below being url/mojo/origin.mojom):

diff --git a/content/common/frame.mojom b/content/common/frame.mojom
index 10c3996185bc..c80126871dbe 100644
--- a/content/common/frame.mojom
+++ b/content/common/frame.mojom
@@ -32,6 +32,10 @@ struct CommonNavigationParams;
 [Native]
 struct RequestNavigationParams;
 
+struct bug {
+  url.mojom.Origin origin;
+};
+
 // Implemented by the frame provider and currently must be associated with the
 // legacy IPC channel.
 interface FrameNavigationControl {

---

The resulting build error looks like the following:

blundell2:src((f41c7c3273b4...)) $  build out/linux_debug/ content/browser
ninja: Entering directory `out/linux_debug/'
[1/1] Regenerating ninja files
[1/116] ACTION //content/common:mojo_bindings__generator(//build/toolchain/linux:clang_x64)
FAILED: gen/content/common/frame.mojom.cc gen/content/common/frame.mojom.h 
python ../../mojo/public/tools/bindings/mojom_bindings_generator.py --use_bundled_pylibs generate ../../content/common/frame.mojom -d ../../ -I ../../ -o gen --bytecode_path gen/mojo/public/tools/bindings --scrambled_message_id_salt_path ../../chrome/VERSION --allow_native_structs -I ../../mojo/services -g c++ --depfile gen/content/common/mojo_bindings__generator_frame.d --depfile_target gen/content/common/frame.mojom.cc --typemap gen/content/common/mojo_bindings__type_mappings --export_attribute CONTENT_EXPORT --export_header content/common/content_export.h --use_once_callback
Traceback (most recent call last):
  File "../../mojo/public/tools/bindings/mojom_bindings_generator.py", line 401, in <module>
    sys.exit(main())
  File "../../mojo/public/tools/bindings/mojom_bindings_generator.py", line 397, in main
    return args.func(args, remaining_args)
  File "../../mojo/public/tools/bindings/mojom_bindings_generator.py", line 285, in _Generate
    processor.ProcessFile(args, remaining_args, generator_modules, filename)
  File "../../mojo/public/tools/bindings/mojom_bindings_generator.py", line 174, in ProcessFile
    RelativePath(filename, args.depth))
  File "../../mojo/public/tools/bindings/mojom_bindings_generator.py", line 207, in _GenerateModule
    AddComputedData(module)
  File "/usr/local/google/home/blundell/chromium/src/mojo/public/tools/bindings/pylib/mojom/generate/generator.py", line 146, in AddComputedData
    _AddStructComputedData(True, struct)
File "/usr/local/google/home/blundell/chromium/src/mojo/public/tools/bindings/pylib/mojom/generate/generator.py", line 87, in _AddStructComputedData
    struct.packed = pack.PackedStruct(struct)
  File "/usr/local/google/home/blundell/chromium/src/mojo/public/tools/bindings/pylib/mojom/generate/pack.py", line 135, in __init__
    src_fields.append(PackedField(field, index, ordinal))
  File "/usr/local/google/home/blundell/chromium/src/mojo/public/tools/bindings/pylib/mojom/generate/pack.py", line 80, in __init__
    self.size = self.GetSizeForKind(field.kind)
  File "/usr/local/google/home/blundell/chromium/src/mojo/public/tools/bindings/pylib/mojom/generate/pack.py", line 59, in GetSizeForKind
    raise Exception("Invalid kind: %s" % kind.spec)
Exception: Invalid kind: x:url.mojom.Origin
 

Comment 1 by roc...@chromium.org, Nov 27 2017

Has nothing to do with typemapping really FYI. I think all undefined
symbols result in cryptic Python stacks.
Summary: [Mojo] Using any symbol in mojom without importing required file gives cryptic error (was: [Mojo] Using typemapped type in mojom without importing required file gives cryptic error)
Yup, you're right. I thought that in the past I had seen decent "missing import" errors in at least some cases, but now when I do the above example with any symbol at all it gives a similar error.
Status: Started (was: Assigned)
Project Member

Comment 4 by bugdroid1@chromium.org, Dec 1 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/826651afbc82de017036c569b2119b1c496dc118

commit 826651afbc82de017036c569b2119b1c496dc118
Author: Yuzhu Shen <yzshen@chromium.org>
Date: Fri Dec 01 02:54:32 2017

Make the generator output easier-to-understand error message for undefined types.

BUG= 788704 

Change-Id: Iedd0fb694e88db9a492f9b670f1e1fd177120a10
Reviewed-on: https://chromium-review.googlesource.com/802402
Reviewed-by: Ken Rockot <rockot@chromium.org>
Commit-Queue: Yuzhu Shen <yzshen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520822}
[modify] https://crrev.com/826651afbc82de017036c569b2119b1c496dc118/mojo/public/tools/bindings/pylib/mojom/generate/pack.py

Status: Fixed (was: Started)
Thanks for the quick turnaround, Yuzhu!

Sign in to add a comment