The grpc_tools_node_protoc error messages are inscrutable.
I tried compiling some protos the other day following the instructions from https://github.com/grpc/grpc/tree/master/examples/node/static_codegen. Not only does it not works, but the error messages are just word soup:
nodejs_static [master ?] -> node_modules/.bin/grpc_tools_node_protoc --js_out=import_style=commonjs,binary:. --grpc_out=. --plugin=protoc-gen-grpc=`node_modules/.bin/grpc_tools_node_protoc_plugin` ../protos/pingpong.proto
/Users/samuelainsworth/Development/grpc-polyglot/nodejs_static/node_modules/grpc-tools/bin/protoc_plugin.js:37
throw error;
^
Error: spawn /Users/samuelainsworth/Development/grpc-polyglot/nodejs_static/node_modules/grpc-tools/bin/grpc_node_plugin ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:232:19)
at onErrorNT (internal/child_process.js:407:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
at startup (internal/bootstrap/node.js:279:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:752:3)
/Users/samuelainsworth/Development/grpc-polyglot/nodejs_static/node_modules/grpc-tools/bin/protoc.js:41
throw error;
^
Error: spawn /Users/samuelainsworth/Development/grpc-polyglot/nodejs_static/node_modules/grpc-tools/bin/protoc ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:232:19)
at onErrorNT (internal/child_process.js:407:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
at startup (internal/bootstrap/node.js:279:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:752:3)
nodejs_static [master ?] ->
If anyone happens to know why this doesn't work, please do let me know. But I'm really here to report that these error messages are very unhelpful.
Repo is here: https://github.com/samuela/grpc-polyglot.
There were some issues adapting the example command, but here's a version that I got working for anyone else's future reference:
node_modules/.bin/grpc_tools_node_protoc --js_out=import_style=commonjs,binary:. --grpc_out=. --plugin=protoc-gen-grpc=node_modules/.bin/grpc_tools_node_protoc_plugin -I=../protos/ ../protos/*
and it's absolutely essential that you run npm rebuild first! Part of the issue was that I was attempting to run a "local" install of grpc-tools, whereas the docs assume a global installation.
But of course the issues with the usability of the error messages still stands.
I'm... sorry, but this error message seems fairly straightforward to me. This is a typical uncaught exception from nodejs, and the exception means that the tool failed to spawn subprocesses, with the filenames it expected but didn't find being right next to the Error: string. I'd agree that it could be nicer of our codebase to catch these exceptions, but I'll have to disagree with the sentiment they are "inscrutable", especially if you have any experience in nodejs programming.
I'm quite comfortable with the layout of stack traces in node.js. My point is that something along the lines of "Failed to launch plugin X because Y" would be a _much_ more helpful message. Part of what makes this error message especially unhelpful is that it shows up even when you run the correct command, but for whatever reason protoc decides that you need to run npm rebuild once more. That's not communicated to the user at all.
The npm rebuild step isn't desirable to be honest. We'd need to figure this one out.
Most helpful comment
There were some issues adapting the example command, but here's a version that I got working for anyone else's future reference:
and it's absolutely essential that you run
npm rebuildfirst! Part of the issue was that I was attempting to run a "local" install of grpc-tools, whereas the docs assume a global installation.But of course the issues with the usability of the error messages still stands.