vscode: askpass-main.js TypeError: Cannot read properties of undefined (reading 'replace')
Might already have a duplicate issue but I did not find one, so I am reporting this (again) here.
Does this issue occur when all extensions are disabled?: Yes
- VS Code Version:
- OS Version:
Version: 1.74.0-insider (user setup)
Commit: 1b1e2a2c5794df1f475976062c754651827634a9
Date: 2022-11-18T05:25:18.342Z
Electron: 19.1.3
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Windows_NT x64 10.0.22621
Sandboxed: Yes
Steps to Reproduce:
- Open a WSL2 project whose git remote url is ssh-based (not http-based)
- Make sure
ssh-agent
has no credential remembered (aka. the next ssh will require password prompt) - Click the Commit button in vscode
- Shows an error dialog, whose git error output is:
> git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file - -S
error: /home/username/.vscode-server-insiders/bin/1b1e2a2c5794df1f475976062c754651827634a9/extensions/git/dist/askpass-main.js:1
(()=>{"use strict";var e={4516:(e,s,r)=>{Object.defineProperty(s,"__esModule",{value:!0}),s.IPCClient=void 0;const t=r(8605);s.IPCClient=class{constructor(e){this.handlerName=e;const s=process.env.VSCODE_GIT_IPC_HANDLE;if(!s)throw new Error("Missing VSCODE_GIT_IPC_HANDLE");this.ipcHandlePath=s}call(e){const s={socketPath:this.ipcHandlePath,path:`/${this.handlerName}`,method:"POST"};return new Promise(((r,n)=>{const o=t.request(s,(e=>{if(200!==e.statusCode)return n(new Error(`Bad status code: ${e.statusCode}`));const s=[];e.on("data",(e=>s.push(e))),e.on("end",(()=>r(JSON.parse(Buffer.concat(s).toString("utf8")))))}));o.on("error",(e=>n(e))),o.write(JSON.stringify(e)),o.end()}))}}},5747:e=>{e.exports=require("fs")},8605:e=>{e.exports=require("http")}},s={};function r(t){var n=s[t];if(void 0!==n)return n.exports;var o=s[t]={exports:{}};return e[t](o,o.exports,r),o.exports}var t={};(()=>{var e=t;Object.defineProperty(e,"__esModule",{value:!0});const s=r(5747),n=r(4516);function o(e){console.error("Missing or invalid credentials."),console.error(e),process.exit(1)}!function(e){if(!process.env.VSCODE_GIT_ASKPASS_PIPE)return o("Missing pipe");if(!process.env.VSCODE_GIT_ASKPASS_TYPE)return o("Missing type");if("https"!==process.env.VSCODE_GIT_ASKPASS_TYPE&&"ssh"!==process.env.VSCODE_GIT_ASKPASS_TYPE)return o(`Invalid type: ${process.env.VSCODE_GIT_ASKPASS_TYPE}`);if("fetch"===process.env.VSCODE_GIT_COMMAND&&process.env.VSCODE_GIT_FETCH_SILENT)return o("Skip silent fetch commands");const r=process.env.VSCODE_GIT_ASKPASS_PIPE,t=process.env.VSCODE_GIT_ASKPASS_TYPE,i="https"===t?e[2]:e[3];let c,a,p;"https"===t&&(c=e[4].replace(/^["']+|["':]+$/g,"")),"ssh"===t&&(/passphrase/i.test(i)?a=e[6].replace(/^["']+|["':]+$/g,""):(c=e[6].replace(/^["']+|["':]+$/g,""),p=e[15])),new n.IPCClient("askpass").call({askpassType:t,request:i,host:c,file:a,fingerprint:p}).then((e=>{s.writeFileSync(r,e+"\n"),setTimeout((()=>process.exit(0)),0)})).catch((e=>o(e)))}(process.argv)})();var n=exports;for(var o in t)n[o]=t[o];t.__esModule&&Object.defineProperty(n,"__esModule",{value:!0})})();
TypeError: Cannot read properties of undefined (reading 'replace')
at /home/username/.vscode-server-insiders/bin/1b1e2a2c5794df1f475976062c754651827634a9/extensions/git/dist/askpass-main.js:1:1709
at /home/username/.vscode-server-insiders/bin/1b1e2a2c5794df1f475976062c754651827634a9/extensions/git/dist/askpass-main.js:1:1966
at /home/username/.vscode-server-insiders/bin/1b1e2a2c5794df1f475976062c754651827634a9/extensions/git/dist/askpass-main.js:1:1982
at Object.<anonymous> (/home/username/.vscode-server-insiders/bin/1b1e2a2c5794df1f475976062c754651827634a9/extensions/git/dist/askpass-main.js:1:2088)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module
fatal: failed to write commit object
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 15
- Comments: 38 (5 by maintainers)
wow, I just figured it out, answering it by myself:
If you run into this problem, make sure you manually add the identity (your private ssh key) to
ssh-agent
like this:Note: The
--apple-use-keychain
option stores the passphrase in your keychain for you when you add an SSH key to thessh-agent
. If you chose not to add a passphrase to your key, run the command without the--apple-use-keychain
option.Run this command after every system reboot and commits will work in VS Code. I guess this whole problem only occurs if you have multiple SSH keypairs in the default location
~/.ssh/id_*
and somehow VS Code only adds the first best to thessh-agent
, so usually~/.ssh/id_rsa
. So, somehow VS Code doesn’t seem to respect theuser.signingkey
global git config. Just guesses… hope this brings you guys further.The solution to work without additional installations for me was to enter the command in Git Bash
git config --global core.sshCommand "SSH_ASKPASS=\"C:\Program Files\Git\mingw64\libexec\git-core\git-gui--askpass\" ssh"
The field of this earned cloning and synchronization with the Git repository through the VS Code interface. My .gitconfig file now looks like this:
The
sshCommand = SSH_ASKPASS=\"C:\\Program Files\\Git\\mingw64\\libexec\\git-core\\git-gui--askpass\"
line was required to solve this problem.ssh-agent
andssh-add ~/.ssh/id_ed25519
did not help with this problem.FYI I am signing my commit using my ssh key, not GPG key