Skip to content
This repository has been archived by the owner on Sep 24, 2021. It is now read-only.

Catch error when calling updateGoPathGoRootFromConfig #17

Closed
wants to merge 1 commit into from

Conversation

simark
Copy link
Collaborator

@simark simark commented Feb 23, 2018

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]

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]>
Copy link
Member

@JanKoehnlein JanKoehnlein left a 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();

Copy link
Member

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.

Copy link
Collaborator Author

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;
Copy link
Member

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?

@JanKoehnlein
Copy link
Member

microsoft#1543

ramya-rao-a pushed a commit to microsoft/vscode-go that referenced this pull request Feb 28, 2018
@simark
Copy link
Collaborator Author

simark commented Feb 28, 2018

Since the issue has been fixed upstream, I will attempt rebase/uplift our code to use the latest vscode-go code.

@simark simark closed this Feb 28, 2018
@JanKoehnlein
Copy link
Member

Rebased

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

Successfully merging this pull request may close these issues.

2 participants