-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Description
The error handling logic for run() assumes the stdout/stderr variables are strings, but in reality they can also be Buffers (source):
vscode-gitlens/src/env/node/git/shell.ts
Lines 248 to 258 in c20ff51
| 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):
vscode-gitlens/src/env/node/git/shell.ts
Lines 161 to 170 in c20ff51
| 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:
- Checking out the latest commit of vscode-gitlens (tested with 2ddb8f0)
- Open project in vscode
- Running
yarn && yarn run rebuildin workspace - Start "Watch & Run" run and debug task
- Wait for the vscode instance to start up
- Open a git workspace in the new vscode instance
- Open a committed file that was created after the initial commit (basically any file)
- Trigger the
>GitLens: Open File at Revision...command - 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
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