Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8ac1e78

Browse files
committed
improve error message on failure to write/rename
1 parentb61468b commit8ac1e78

File tree

2 files changed

+70
-5
lines changed

2 files changed

+70
-5
lines changed

‎src/sshConfig.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,3 +607,52 @@ Host coder-vscode.dev.coder.com--*
607607
)
608608
expect(mockFileSystem.rename).toBeCalledWith(expect.stringMatching(sshTempFilePathExpr),sshFilePath)
609609
})
610+
611+
it("fails if we are unable to write the temporary file",async()=>{
612+
constexistentSSHConfig=`Host beforeconfig
613+
HostName before.config.tld
614+
User before`
615+
616+
constsshConfig=newSSHConfig(sshFilePath,mockFileSystem)
617+
mockFileSystem.readFile.mockResolvedValueOnce(existentSSHConfig)
618+
mockFileSystem.stat.mockResolvedValueOnce({mode:0o600})
619+
mockFileSystem.writeFile.mockRejectedValueOnce(newError("EACCES"))
620+
621+
awaitsshConfig.load()
622+
623+
expect(mockFileSystem.readFile).toBeCalledWith(sshFilePath,expect.anything())
624+
awaitexpect(
625+
sshConfig.update("dev.coder.com",{
626+
Host:"coder-vscode.dev.coder.com--*",
627+
ProxyCommand:"some-command-here",
628+
ConnectTimeout:"0",
629+
StrictHostKeyChecking:"no",
630+
UserKnownHostsFile:"/dev/null",
631+
LogLevel:"ERROR",
632+
}),
633+
).rejects.toThrow(/FailedtowritetemporarySSHconfigfile.*EACCES/)
634+
})
635+
636+
it("fails if we are unable to rename the temporary file",async()=>{
637+
constexistentSSHConfig=`Host beforeconfig
638+
HostName before.config.tld
639+
User before`
640+
641+
constsshConfig=newSSHConfig(sshFilePath,mockFileSystem)
642+
mockFileSystem.readFile.mockResolvedValueOnce(existentSSHConfig)
643+
mockFileSystem.stat.mockResolvedValueOnce({mode:0o600})
644+
mockFileSystem.writeFile.mockResolvedValueOnce("")
645+
mockFileSystem.rename.mockRejectedValueOnce(newError("EACCES"))
646+
647+
awaitsshConfig.load()
648+
awaitexpect(
649+
sshConfig.update("dev.coder.com",{
650+
Host:"coder-vscode.dev.coder.com--*",
651+
ProxyCommand:"some-command-here",
652+
ConnectTimeout:"0",
653+
StrictHostKeyChecking:"no",
654+
UserKnownHostsFile:"/dev/null",
655+
LogLevel:"ERROR",
656+
}),
657+
).rejects.toThrow(/FailedtorenametemporarySSHconfigfile.*EACCES/)
658+
})

‎src/sshConfig.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,27 @@ export class SSHConfig {
242242
constfileName=path.basename(this.filePath)
243243
constdirName=path.dirname(this.filePath)
244244
consttempFilePath=`${dirName}/.${fileName}.vscode-coder-tmp.${randSuffix}`
245-
awaitthis.fileSystem.writeFile(tempFilePath,this.getRaw(),{
246-
mode:existingMode,
247-
encoding:"utf-8",
248-
})
249-
awaitthis.fileSystem.rename(tempFilePath,this.filePath)
245+
try{
246+
awaitthis.fileSystem.writeFile(tempFilePath,this.getRaw(),{
247+
mode:existingMode,
248+
encoding:"utf-8",
249+
})
250+
}catch(err){
251+
thrownewError(
252+
`Failed to write temporary SSH config file at${tempFilePath}:${errinstanceofError ?err.message :String(err)}. `+
253+
`Please check your disk space, permissions, and that the directory exists.`,
254+
)
255+
}
256+
257+
try{
258+
awaitthis.fileSystem.rename(tempFilePath,this.filePath)
259+
}catch(err){
260+
thrownewError(
261+
`Failed to rename temporary SSH config file at${tempFilePath} to${this.filePath}:${
262+
errinstanceofError ?err.message :String(err)
263+
}. Please check your disk space, permissions, and that the directory exists.`,
264+
)
265+
}
250266
}
251267

252268
publicgetRaw(){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp