protobufjs / protobuf.js

Protocol Buffers for JavaScript & TypeScript.
Other
9.83k stars 1.41k forks source link

TypeError: Cannot read property 'remove' of null #1165

Open ashubham opened 5 years ago

ashubham commented 5 years ago

protobuf.js version: 6.8.3

When using --sparse option in the pbjs CLI command. It fails with an error

TypeError: Cannot read property 'remove' of null

pbjs -p ../ <proto_files> -t static-module -w es6 --sparse --force-message > out.js
at Root._handleRemove (/Users/ashish.shubham/code/thoughtspot/blink/node_modules/protobufjs/src/root.js:320:46)
    at Root._handleRemove (/Users/ashish.shubham/code/thoughtspot/blink/node_modules/protobufjs/src/root.js:338:18)
    at Type.onRemove (/Users/ashish.shubham/code/thoughtspot/blink/node_modules/protobufjs/src/object.js:131:14)
    at Namespace.remove (/Users/ashish.shubham/code/thoughtspot/blink/node_modules/protobufjs/src/namespace.js:263:12)
    at /Users/ashish.shubham/code/thoughtspot/blink/node_modules/protobufjs/cli/pbjs.js:284:28
    at traverse (/Users/ashish.shubham/code/thoughtspot/blink/node_modules/protobufjs/cli/util.js:47:5)
    at /Users/ashish.shubham/code/thoughtspot/blink/node_modules/protobufjs/cli/util.js:62:13
    at Array.forEach (<anonymous>)
    at traverse (/Users/ashish.shubham/code/thoughtspot/blink/node_modules/protobufjs/cli/util.js:61:29)
    at /Users/ashish.shubham/code/thoughtspot/blink/node_modules/protobufjs/cli/util.js:62:13

    at checkExecSyncError (child_process.js:611:11)
    at Object.execSync (child_process.js:648:13)
JustinBeckwith commented 5 years ago

Greetings! Can you share the proto files you're using to get this?

cyrilis commented 5 years ago

Hi @JustinBeckwith

I came into same error, and I uploaded the proto file I use.

pbjs --sparse -p "$GOPATH/src/github.com/gogo/protobuf" -p . -t json test.proto

Proto Files: two-proto-files.zip

Thanks!

natiz commented 4 years ago

+1

acrazing commented 4 years ago

I meet this again, it seems occurs when process extensions:

I import gogo/protobuf/gogo.proto to optimize emitted code, then it throws the error, I found it throws when process the extensionField:

image

image

acrazing commented 4 years ago

The minimum code to reproduce the error:

syntax = "proto3";
package stmp.examples.gomoku;

option go_package = "github.com/acrazing/stmp-go/examples/gomoku/gomoku_pb;pb";

import "github.com/envoyproxy/protoc-gen-validate/validate/validate.proto";
//import "stmp/stmp.proto";

// disable this for avoid pbjs throws error
import "github.com/gogo/protobuf/gogoproto/gogo.proto";

option (gogoproto.description_all) = false;
option (gogoproto.goproto_unrecognized_all) = false;
option (gogoproto.goproto_extensions_map_all) = false;
option (gogoproto.goproto_unkeyed_all) = false;
option (gogoproto.goproto_sizecache_all) = false;

message Empty {
}

execute:

    yarn pbjs -t static-module -w commonjs -p ./vendor -p . \
        --no-create --no-verify \
        --no-convert --no-delimited --keep-case --sparse \
        -o ./examples/gomoku/gomoku_pb/gomoku.pb.js ./examples/gomoku/gomoku_pb/*.proto
aSapien commented 4 years ago

Still happening with version 6.10.1

ping-localhost commented 3 years ago

For me adding the following was enough to resolve the issue:

if (object.extensionField.parent !== null) {
    object.extensionField.parent.remove(object.extensionField);
}

No idea if that's good enough to open a merge request with though.