Skip to content

Commit f0c87a6

Browse files
committed
src/util,goInstallTools: log 'cwd'
Some users are experiencing ENOENT errors while running `go version` or `go env` commands even though the go binary exists. Another reason that users are experiencing the issue is `cwd` doesn't exist. Add extra logging in the failure message to debug the issue. For golang/vscode#774 Change-Id: I80ecc39b5e1a23f225eb914a87bd196e814acac0 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/263978 Trust: Hyang-Ah Hana Kim <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Suzy Mueller <[email protected]>
1 parent b712568 commit f0c87a6

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/goInstallTools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ export function updateGoVarsFromConfig(): Promise<void> {
367367
{ env: toolExecutionEnvironment(), cwd: getWorkspaceFolderPath() },
368368
(err, stdout, stderr) => {
369369
if (err) {
370-
outputChannel.append(`Failed to run '${goRuntimePath} env' : ${err}\n${stderr}`);
370+
outputChannel.append(`Failed to run '${goRuntimePath} env' (cwd: ${getWorkspaceFolderPath()}): ${err}\n${stderr}`);
371371
outputChannel.show();
372372

373373
vscode.window.showErrorMessage(`Failed to run '${goRuntimePath} env. The config change may not be applied correctly.`);

src/util.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,12 @@ export async function getGoVersion(goBinPath?: string): Promise<GoVersion | unde
348348
}
349349
warn(`cached Go version (${JSON.stringify(cachedGoVersion)}) is invalid, recomputing`);
350350
}
351+
const docUri = vscode.window.activeTextEditor?.document.uri;
352+
const cwd = getWorkspaceFolderPath(docUri && docUri.fsPath.endsWith('.go') ? docUri : undefined);
353+
351354
let goVersion: GoVersion;
352355
try {
353356
const env = toolExecutionEnvironment();
354-
const docUri = vscode.window.activeTextEditor?.document.uri;
355-
const cwd = getWorkspaceFolderPath(docUri && docUri.fsPath.endsWith('.go') ? docUri : undefined);
356357
const execFile = util.promisify(cp.execFile);
357358
const { stdout, stderr } = await execFile(goRuntimePath, ['version'], { env, cwd });
358359
if (stderr) {
@@ -361,7 +362,7 @@ export async function getGoVersion(goBinPath?: string): Promise<GoVersion | unde
361362
}
362363
goVersion = new GoVersion(goRuntimePath, stdout);
363364
} catch (err) {
364-
warn(`failed to run "${goRuntimePath} version": ${err}`);
365+
warn(`failed to run "${goRuntimePath} version": ${err} cwd: ${cwd}`);
365366
return;
366367
}
367368
if (!goBinPath) { // if getGoVersion was called with a given goBinPath, don't cache the result.

0 commit comments

Comments
 (0)