Skip to content

Error on toObject when a message has a nested messge with unordered value #729

Description

@yagop

protobuf.js version: master (tested on 8de21e1)

I know master branch is not published but I want to report this behavior, maybe is unknown. In 6.6.5 is working fine.

const protobuf = require("protobufjs");

const proto = `
package main;

message Foo {
  optional Bar bar = 2;
  optional string a = 1;
  message Bar {
  }
}
`

const root = protobuf.parse(proto).root;

const Foo = root.lookupType('main.Foo');

const foo = Foo.create({
  bar: Foo.Bar.create({})
});

const buffer = Foo.encode(foo).finish();
const msg = Foo.decode(buffer);
console.log(Foo.toObject(msg));
➜ node test.js                                                         
undefined:15
		d["bar"]=types[1].toObject(m["bar"],o)
		                 ^

TypeError: Cannot read property 'toObject' of null
    at Type._main_Foo$toObject [as toObject] (eval at eof (/tmp/tmp.smwHGIzVCY/node_modules/@protobufjs/codegen/index.js:103:25), <anonymous>:15:20)
    at Object.<anonymous> (/tmp/tmp.smwHGIzVCY/test.js:24:17)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:425:7)
    at startup (bootstrap_node.js:146:9)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions