Skip to content
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

Errors thrown by run() git shell helper are not properly handled #2823

Closed
mogelbrod opened this issue Jul 20, 2023 · 1 comment · Fixed by #2824
Closed

Errors thrown by run() git shell helper are not properly handled #2823

mogelbrod opened this issue Jul 20, 2023 · 1 comment · Fixed by #2824
Assignees
Labels
bug Something isn't working
Milestone

Comments

@mogelbrod
Copy link
Contributor

Description

The error handling logic for run() assumes the stdout/stderr variables are strings, but in reality they can also be Buffers (source):

let stdoutDecoded;
let stderrDecoded;
if (encoding === 'utf8' || encoding === 'binary' || encoding === 'buffer') {
stdoutDecoded = stdout;
stderrDecoded = stderr;
} else {
const decode = (await import(/* webpackChunkName: "encoding" */ 'iconv-lite')).decode;
stdoutDecoded = decode(Buffer.from(stdout, 'binary'), encoding);
stderrDecoded = decode(Buffer.from(stderr, 'binary'), encoding);
}
reject(new RunError(error, stdoutDecoded, stderrDecoded));

When this happens the RunError constructor throws while trying to call .trim() on the buffer instance(s), which leads to the original error being shadowed (and not logged):

export class RunError extends Error {
constructor(
private readonly original: ExecException,
public readonly stdout: string,
public readonly stderr: string,
) {
super(original.message);
stdout = stdout.trim();
stderr = stderr.trim();

I encountered this while working on a PR for #708. I can consistently reproduce this by:

  1. Checking out the latest commit of vscode-gitlens (tested with 2ddb8f0)
  2. Open project in vscode
  3. Running yarn && yarn run rebuild in workspace
  4. Start "Watch & Run" run and debug task
  5. Wait for the vscode instance to start up
  6. Open a git workspace in the new vscode instance
  7. Open a committed file that was created after the initial commit (basically any file)
  8. Trigger the >GitLens: Open File at Revision... command
  9. Select any tag or commit at which the opened file didn't exist

Nothing visibly happens, but the debug log outputs:

[GitLens] [  639] GitFileSystemProvider.stat failed [7ms] EntryNotFound (FileSystemError): gitlens://7b22726566223a22666561742f746f61737473222c227265706f50617468223a222f55736572732f766963746f722f7372632f627573696e657373227d/{...PATH TO FILE....}?{"ref":"{SELECTED REF}"}
	at GitFileSystemProvider.stat (.../src/vscode-gitlens/dist/gitlens.js:29221:65) {code: 'FileNotFound', name: 'EntryNotFound (FileSystemError)', stack: 'EntryNotFound (FileSystemError): gitlens://7b…/src/vscode-gitlens/dist/gitlens.js:29221:65)', message: 'gitlens://7b22726566223a22666561742f746f6173…{...PATH TO FILE....}?{"ref":"{SELECTED REF}"}'}

logger.ts:115
rejected promise not handled within 1 second: TypeError: stdout.trim is not a function
extensionHostProcess.js:105
stack trace: TypeError: stdout.trim is not a function
	at new RunError (.../src/vscode-gitlens/dist/gitlens.js:26028:21)
	at .../src/vscode-gitlens/dist/gitlens.js:26087:16
	at ChildProcess.exithandler (node:child_process:417:5)
	at ChildProcess.emit (node:events:513:28)
	at maybeClose (node:internal/child_process:1121:16)
	at Socket.<anonymous> (node:internal/child_process:479:11)
	at Socket.emit (node:events:513:28)
	at Pipe.<anonymous> (node:net:757:14)
	at Pipe.callbackTrampoline (node:internal/async_hooks:130:17)

GitLens Version

2ddb8f0

VS Code Version

Version: 1.80.1
Commit: 74f6148eb9ea00507ec113ec51c489d6ffb4b771
Date: 2023-07-12T17:20:58.115Z (1 wk ago)
Electron: 22.3.14
ElectronBuildId: 21893604
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Darwin arm64 22.5.0

Git Version

2.39.1

Logs, Screenshots, Screen Captures, etc

No response

@mogelbrod mogelbrod added bug Something isn't working triage Needs to be looked at labels Jul 20, 2023
mogelbrod added a commit to mogelbrod/vscode-gitlens that referenced this issue Jul 20, 2023
@eamodio eamodio removed the triage Needs to be looked at label Jul 20, 2023
@eamodio eamodio self-assigned this Jul 20, 2023
@eamodio eamodio added this to the 14.2 milestone Jul 20, 2023
eamodio pushed a commit to mogelbrod/vscode-gitlens that referenced this issue Jul 20, 2023
@eamodio eamodio added the pending-release Resolved but not yet released to the stable edition label Jul 20, 2023
@eamodio eamodio removed the pending-release Resolved but not yet released to the stable edition label Aug 8, 2023
@github-actions
Copy link

github-actions bot commented Sep 7, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants