-
Notifications
You must be signed in to change notification settings - Fork 12
Catch error when calling updateGoPathGoRootFromConfig #17
Conversation
If the go binary is not available from the PATH, the server outputs this error message. server --> client: b'{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":1,"message":"[lspserver] (node:17641) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): TypeError: \\"file\\" argument must be a non-empty string"}}' server --> client: b'{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":1,"message":"[lspserver] (node:17641) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code."}}' The TypeError comes from node's child_process.execFile when the vscode-go code tries to run the go binary, because goRuntimePath's value is undefined. This patch makes updateGoPathGoRootFromConfig return a rejected promise with a meaningful error message when the go binary is not found, and then makes the server send an error message to the client including the error and backtrace. The result looks like this: server --> client: b'{"jsonrpc":"2.0","method":"window/showMessage","params":{"type":1,"message":"Error: Cannot find \\"go\\" binary. Update PATH or GOROOT appropriately\\n at Object.updateGoPathGoRootFromConfig (/home/emaisin/src/go-language-server/out/src/goInstallTools.js:280:31)\\n at Object.<anonymous> (/home/emaisin/src/go-language-server/out/src-vscode-mock/activate.js:105:33)\\n at Generator.next (<anonymous>)\\n at /home/emaisin/src/go-language-server/out/src-vscode-mock/activate.js:13:71\\n at new Promise (<anonymous>)\\n at __awaiter (/home/emaisin/src/go-language-server/out/src-vscode-mock/activate.js:9:12)\\n at Object.activate (/home/emaisin/src/go-language-server/out/src-vscode-mock/activate.js:34:12)\\n at LspServer.<anonymous> (/home/emaisin/src/go-language-server/out/src-vscode-mock/lsp-server.js:93:31)\\n at Generator.next (<anonymous>)\\n at /home/emaisin/src/go-language-server/out/src-vscode-mock/lsp-server.js:13:71"}}' It's not very readable as-is, but I suppose that when the client prints it in a log, the \n will be presented as real line breaks. But the important thing is that the info is there, so that one has a lead to start debugging. There was another instance (in runTool) where the result of getGoRuntimePath was not checked, so it generated a similar unclear error. Fixes theia-ide#16 Signed-off-by: Simon Marchi <[email protected]>
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.
Consider filing a PR against vscode-go
@@ -290,6 +290,11 @@ export function updateGoPathGoRootFromConfig(): Promise<void> { | |||
|
|||
// If GOPATH is still not set, then use the one from `go env` | |||
let goRuntimePath = getGoRuntimePath(); | |||
|
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.
This could go into vscode-go. Have you considered posting a PR there? I try to keep the possibility to rebase without major problems for as long as possible.
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.
It is complicated for us (long/complicated/dumb corporate procedures) to contribute to other projects than those we've been specifically allowed to. Can you open a PR yourself instead?
@@ -559,7 +559,18 @@ export interface ICheckResult { | |||
*/ | |||
export function runTool(args: string[], cwd: string, severity: string, useStdErr: boolean, toolName: string, env: any, printUnexpectedOutput: boolean, token?: vscode.CancellationToken): Promise<ICheckResult[]> { | |||
let goRuntimePath = getGoRuntimePath(); | |||
let cmd = toolName ? getBinPath(toolName) : goRuntimePath; | |||
let cmd; |
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.
Same as above: Could vscode-go benefit from that change as well?
#17 Signed-off-by: Jan Koehnlein <[email protected]>
theia-ide#17 Signed-off-by: Jan Koehnlein <[email protected]>
Since the issue has been fixed upstream, I will attempt rebase/uplift our code to use the latest vscode-go code. |
Rebased |
If the go binary is not available from the PATH, the server outputs this
error message.
server --> client: b'{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":1,"message":"[lspserver] (node:17641) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): TypeError: \"file\" argument must be a non-empty string"}}'
server --> client: b'{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":1,"message":"[lspserver] (node:17641) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code."}}'
The TypeError comes from node's child_process.execFile when the
vscode-go code tries to run the go binary, because goRuntimePath's value
is undefined.
This patch makes updateGoPathGoRootFromConfig return a rejected promise
with a meaningful error message when the go binary is not found, and
then makes the server send an error message to the client including the
error and backtrace. The result looks like this:
server --> client: b'{"jsonrpc":"2.0","method":"window/showMessage","params":{"type":1,"message":"Error: Cannot find \"go\" binary. Update PATH or GOROOT appropriately\n at Object.updateGoPathGoRootFromConfig (/home/emaisin/src/go-language-server/out/src/goInstallTools.js:280:31)\n at Object. (/home/emaisin/src/go-language-server/out/src-vscode-mock/activate.js:105:33)\n at Generator.next ()\n at /home/emaisin/src/go-language-server/out/src-vscode-mock/activate.js:13:71\n at new Promise ()\n at __awaiter (/home/emaisin/src/go-language-server/out/src-vscode-mock/activate.js:9:12)\n at Object.activate (/home/emaisin/src/go-language-server/out/src-vscode-mock/activate.js:34:12)\n at LspServer. (/home/emaisin/src/go-language-server/out/src-vscode-mock/lsp-server.js:93:31)\n at Generator.next ()\n at /home/emaisin/src/go-language-server/out/src-vscode-mock/lsp-server.js:13:71"}}'
It's not very readable as-is, but I suppose that when the client
prints it in a log, the \n will be presented as real line breaks. But
the important thing is that the info is there, so that one has a lead to
start debugging.
There was another instance (in runTool) where the result of
getGoRuntimePath was not checked, so it generated a similar unclear
error.
Fixes #16
Signed-off-by: Simon Marchi [email protected]