neovim / node-client

Nvim Node.js client and plugin host
https://neovim.io/node-client/
MIT License
464 stars 49 forks source link

E475: Invalid argument: Channel doesn't exist #279

Closed ziontee113 closed 5 months ago

ziontee113 commented 5 months ago

Hi. I run into channel related issues whenever I use any type console.log().

If console.log() gets ran in my code, it will work the first time, then the second time it will throw E475: Invalid argument: Channel doesn't exist

Also logging doesn't work for me. It does create a log file but doesn't write anything into it.

The ONLY way that I can log stuffs is to use console.error(). Anything else like console.info, console.debug, etc... will be met with `E475: Invalid argument: Channel doesn't exist or Invalid Channel error.

I'm currently using the Devtool to see the console output.

ziontee113 commented 5 months ago

Turns out I can also use console.warn, which won't produce the channel errors and crash the plugin.

justinmk commented 5 months ago

If console.log() gets ran in my code, it will work the first time, then the second time it will throw E475: Invalid argument: Channel doesn't exist

stdout is used for the RPC channel, so writing to it will break the channel which only accepts msgpack-rpc.

Turns out I can also use console.warn, which won't produce the channel errors and crash the plugin.

presumably, that writes to stderr instead of stdout

ziontee113 commented 5 months ago

Thank you @justinmk for explaining. However I'm confused due to the example is using console.log here https://github.com/neovim/node-client/blob/master/examples/decorators.md

Should I not use console.log at all while developing plugin using Javascript? Thank you.

justinmk commented 5 months ago

the example is using console.log here https://github.com/neovim/node-client/blob/master/examples/decorators.md

That doc should be fixed, would you mind sending a PR? Either console.error or possibly process.stderr.write() should be better.