-
Notifications
You must be signed in to change notification settings - Fork 53
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
feat(transport): show contents of invalid RPC message in TypeError #404
Conversation
resolved.value == null | ||
? 'null or undefined' | ||
: typeof resolved.value; | ||
this.logger.debug( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be safe, let's not involve the logger. this is low-level code and we don't want to get into loops or anything like that.
- instead of printing the type, let's print the actual
resolved.value
use node.util.inspect.- example:
node-client/packages/neovim/src/utils/logger.ts
Lines 2 to 21 in b05c7e6
import { inspect } from 'node:util'; const level = process.env.NVIM_NODE_LOG_LEVEL || 'debug'; const loggerKeys = ['info', 'warn', 'error', 'debug', 'level'] as const; export type Logger = Pick<winston.Logger, (typeof loggerKeys)[number]>; function getFormat(colorize: boolean) { return winston.format.combine( winston.format.splat(), winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss', }), winston.format.printf(info => { let msg: string; try { msg = typeof info.message === 'object' ? inspect(info.message, false, 2, colorize) : info.message;
- example:
- to be extra safe, let's wrap the inspect() in a try-catch.
let valstr = '?'
try {
valstr = inspect(resolved.value, { sorted: true, maxArrayLength: 10, maxStringLength: 500, compact: true, breakLength = 500 })
} catch {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think now? I put a console.error within the new catch block since I don't like the idea of swallowing the error.
Also do I need to add unit tests to pass CI for this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put a console.error within the new catch block since I don't like the idea of swallowing the error.
That's usually a good instinct, but in this case the failure will be signaled because we'll show "?" in the thrown error. And this should be rare, so better to wait until it's a problem since this is a low-level codepath.
will push some updates then merge and release |
f91377f
to
19e2000
Compare
19e2000
to
20ceff4
Compare
Problem: Exception does not give any hint about the contents of an invalid RPC message: "TypeError: expected msgpack result to be array" Solution: Show the payload contents in the error message. Example: "TypeError: expected msgpack array, got: …"
20ceff4
to
59136a4
Compare
related: vscode-neovim/vscode-neovim#2184