fix(terminal): catch ENOPRO in getCwdResource when file:// provider absent in VS Code web#317780
Open
mutl3y wants to merge 2 commits into
Open
fix(terminal): catch ENOPRO in getCwdResource when file:// provider absent in VS Code web#317780mutl3y wants to merge 2 commits into
mutl3y wants to merge 2 commits into
Conversation
…bsent in VS Code web In VS Code web (server-linux-x64-web accessed via browser), when remoteAuthority is falsy from the terminal's perspective, getCwdResource() falls through to URI.file(cwd) which produces a file:// URI. The browser FileService has no file:// provider registered — only the remote provider — so _fileService.exists() throws ENOPRO (No file system provider found for resource 'file:///...'). This causes the Copilot agent terminal tool (and any other caller of getCwdResource) to fail on every invocation in self-hosted server-linux-x64-web deployments. The fix wraps the function body in try/catch so that ENOPRO (or any provider error) returns undefined, allowing callers to fall back to the default CWD gracefully. The underlying issue is that the else branch (URI.file) is desktop/Electron-only code that is unreachable in a correct web context: when remoteAuthority is properly set by the server, _pathService.fileURI() is used instead. In server-linux-x64-web without an explicit remoteAuthority header the else branch fires incorrectly. Fixes: terminal getCwdResource ENOPRO in server-linux-x64-web / browser context
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the terminal instance working-directory URI resolution in VS Code web/server scenarios by preventing getCwdResource() from throwing when the FileService cannot handle the produced URI (notably when a file:// provider is absent), allowing callers (including agent terminal tools) to fall back gracefully.
Changes:
- Wrap
TerminalInstance.getCwdResource()URI creation/existence validation intry/catch. - Return
undefinedinstead of propagating provider-related errors (e.g. ENOPRO) fromfileService.exists.
Comment on lines
+2372
to
2391
| try { | ||
| if (this.remoteAuthority) { | ||
| resource = await this._pathService.fileURI(cwd); | ||
| } else { | ||
| // Note: in VS Code web (server-linux-x64-web accessed via browser), | ||
| // remoteAuthority is falsy from the terminal's perspective, so URI.file() | ||
| // is used here. However, the browser FileService has no file:// provider | ||
| // registered, causing an ENOPRO error. We catch it so that callers receive | ||
| // undefined and fall back gracefully to the default CWD. | ||
| resource = URI.file(cwd); | ||
| } | ||
| if (await this._fileService.exists(resource)) { | ||
| return resource; | ||
| } | ||
| } catch { | ||
| // FileService provider not available for this URI scheme (e.g. file:// in | ||
| // VS Code web where only the remote provider is registered). Return undefined | ||
| // so callers fall back to the default CWD rather than propagating the error. | ||
| return undefined; | ||
| } |
Comment on lines
+2383
to
+2390
| if (await this._fileService.exists(resource)) { | ||
| return resource; | ||
| } | ||
| } catch { | ||
| // FileService provider not available for this URI scheme (e.g. file:// in | ||
| // VS Code web where only the remote provider is registered). Return undefined | ||
| // so callers fall back to the default CWD rather than propagating the error. | ||
| return undefined; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #317329 (related — same deployment scenario, different subsystem)
When using VS Code Server (
server-linux-x64-web) accessed via a browser, callinggetCwdResource()on a terminal instance throws:This surfaces as a failure on every Copilot agent terminal tool invocation (the agent host calls
getCwdResource()to resolve the working directory before running a shell command). Any other caller that relies on this method is similarly broken.Root cause
getCwdResource()interminalInstance.tshas two branches:In a self-hosted
server-linux-x64-webdeployment without an explicitremoteAuthorityheader,this.remoteAuthorityis falsy from the terminal's perspective. Theelsebranch fires, producing afile:///workspaceURI. The browserFileServicehas nofile://provider registered — only the remote provider — so_fileService.exists(resource)throwsENOPRO.This
elsebranch is desktop/Electron-only code: in a correct remote-web contextremoteAuthoritywould be set and_pathService.fileURI()would be used instead.Fix
Wrap the function body in
try/catchso that provider errors (ENOPRO or otherwise) returnundefined, allowing callers to fall back to the default CWD rather than propagating the error. The existing logic is preserved — only the error path is changed.Testing
Verified against a running
server-linux-x64-webinstance (v1.121.0, commitf6cfa2ea) in a containerised deployment:getCwdResourcereturnsundefinedand the tool falls back to the default CWDNotes
src/vs/workbench/contrib/terminal/browser/terminalInstance.ts_pathService.fileURI(); this PR takes the minimal safe approach of catching the error