ts-proto icon indicating copy to clipboard operation
ts-proto copied to clipboard

`outputSchema=true` throwing when compiling `googleapis` protos

Open rosslavery opened this issue 1 year ago • 1 comments
trafficstars

Hi there,

Running with the following options is throwing with the below error.

protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto \
  --experimental_allow_proto3_optional \
  --proto_path $path \
  --ts_proto_out=$outdir \
  --ts_proto_opt=outputSchema=true \
  ./google/ads/googleads/$version/**/*.proto
FAILED!Cannot read properties of undefined (reading '17')TypeError: Cannot read properties of undefined (reading '17')
    at encodedOptionsToOptions (/Users/someuser/Desktop/Work/somerepo/node_modules/.pnpm/[email protected]/node_modules/ts-proto/build/schema.js:191:51)
    at /Users/someuser/Desktop/Work/somerepo/node_modules/.pnpm/[email protected]/node_modules/ts-proto/build/schema.js:203:34
    at Array.forEach (<anonymous>)
    at resolveMessageOptions (/Users/someuser/Desktop/Work/somerepo/node_modules/.pnpm/[email protected]/node_modules/ts-proto/build/schema.js:201:19)
    at /Users/someuser/Desktop/Work/somerepo/node_modules/.pnpm/[email protected]/node_modules/ts-proto/build/schema.js:86:33
    at Array.forEach (<anonymous>)
    at generateSchema (/Users/someuser/Desktop/Work/somerepo/node_modules/.pnpm/[email protected]/node_modules/ts-proto/build/schema.js:85:34)
    at generateFile (/Users/someuser/Desktop/Work/somerepo/node_modules/.pnpm/[email protected]/node_modules/ts-proto/build/main.js:252:52)
    at /Users/someuser/Desktop/Work/somerepo/node_modules/.pnpm/[email protected]/node_modules/ts-proto/build/plugin.js:43:54
    at Array.map (<anonymous>)--ts_proto_out: protoc-gen-ts_proto: Plugin failed with status code 1.

Which points to this line (reading '17' of extensionCache[extendee]):

const extension = extensionCache[extendee][parseInt(key, 10) >>> 3];

Looking to output the schema to use in some downstream tooling, but not having any luck 🙃

rosslavery avatar Dec 08 '23 20:12 rosslavery

I found that protoc 22.3 is the last version without this throw, protoc 23.0 onward has this issue.

tmtd4c93aac avatar Apr 16 '24 14:04 tmtd4c93aac

Any chance this can be fixed ? Getting same error.

shubhamshah207 avatar Jul 04 '24 01:07 shubhamshah207

Experiencing the same with [email protected] and my own protos. There are a number of cases where extensionCache[extendee] is undefined, and I was able to hack around the problem and get it to compile by modifying the code in question to:

const extension = extensionCache[extendee]?.[parseInt(key, 10) >>> 3];
if (extension) {
    resultOptions.push(getExtensionValue(ctx, extension, value));
}

Unsure yet if this produces good behavior or breaks some assumptions.

rektdeckard avatar Jul 31 '24 05:07 rektdeckard