Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: illegal token in proto file which can be used normally #1799

Open
antonilol opened this issue Aug 31, 2022 · 2 comments
Open

Error: illegal token in proto file which can be used normally #1799

antonilol opened this issue Aug 31, 2022 · 2 comments

Comments

@antonilol
Copy link

protobuf.js version: 7.1.0

i get an error when generating typescript types with a proto file that works normally with loadSync and older grpc.load. is this the right place to post this? the stack trace says the error occurred in protobufjs

# not js, this is shell script
# download LND proto file
wget -O lightning.proto https://raw.githubusercontent.com/lightningnetwork/lnd/b208642caf96b5753e9e295450a26917e1b0bb0b/lnrpc/lightning.proto
# try generate typescript types
npx proto-loader-gen-types --keepCase --longs=String --enums=String --defaults --oneofs --grpcLib=@grpc/grpc-js --outDir=types lightning.proto

(proto-loader-gen-types is from @grpc/proto-loader)

Error: illegal token 'PendingChannels' (lightning.proto, line 153)
    at illegal (/tmp/node_modules/protobufjs/src/parse.js:96:16)
    at parseService_block (/tmp/node_modules/protobufjs/src/parse.js:699:23)
    at ifBlock (/tmp/node_modules/protobufjs/src/parse.js:290:17)
    at parseService (/tmp/node_modules/protobufjs/src/parse.js:691:9)
    at parseCommon (/tmp/node_modules/protobufjs/src/parse.js:269:17)
    at parse (/tmp/node_modules/protobufjs/src/parse.js:829:21)
    at process (/tmp/node_modules/protobufjs/src/root.js:127:30)
    at /tmp/node_modules/protobufjs/src/root.js:194:17
    at fetchReadFileCallback (/tmp/node_modules/@protobufjs/fetch/index.js:51:19)
    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3)

i noticed (and use this as a workaround now) that removing all // comments makes it work:

sed -Ei '/^ +\/\/.*/d' lightning.proto
@alexander-fenster
Copy link
Contributor

Repro:

> root.loadSync('lightning.proto', {alternateCommentMode: true})
Uncaught Error: illegal token 'PendingChannels' (lightning.proto, line 153)
    at illegal (/private/tmp/lightning/node_modules/protobufjs/src/parse.js:96:16)
    at parseService_block (/private/tmp/lightning/node_modules/protobufjs/src/parse.js:699:23)
    at ifBlock (/private/tmp/lightning/node_modules/protobufjs/src/parse.js:290:17)
    at parseService (/private/tmp/lightning/node_modules/protobufjs/src/parse.js:691:9)
    at parseCommon (/private/tmp/lightning/node_modules/protobufjs/src/parse.js:269:17)
    at parse (/private/tmp/lightning/node_modules/protobufjs/src/parse.js:829:21)
    at process (/private/tmp/lightning/node_modules/protobufjs/src/root.js:127:30)
    at fetch (/private/tmp/lightning/node_modules/protobufjs/src/root.js:178:13)
    at Root.load (/private/tmp/lightning/node_modules/protobufjs/src/root.js:206:13)
    at Root.loadSync (/private/tmp/lightning/node_modules/protobufjs/src/root.js:247:17)

@alexander-fenster
Copy link
Contributor

So this is caused by alternateCommentMode being enabled by @grpc/proto-loader. Your proto file has a mix of // and /* ... */ comments, which apparently confuses the parser. I won't be able to look into this deeper soon enough, but should you have a fix, please feel free to contribute :)

Cc: @murgatroid99 - FYI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants