Skip to content

Commit 572a938

Browse files
committed
adjust error mesages to provide more useful output
1 parent 752a2a8 commit 572a938

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

src/sshConfig.test.ts

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,59 @@ Host afterconfig
300300
LogLevel: "ERROR",
301301
}),
302302
).rejects.toThrow(
303-
`Malformed config: ssh config has 2 dev.coder.com START comments but 1 dev.coder.com END comments. Each START must have a matching END.`,
303+
`Malformed config: Unterminated START CODER VSCODE dev.coder.com block: Each START block must have an END block.`,
304304
)
305305
})
306306

307+
it("throws an error if there is a mismatched start and end block count (without label)", async () => {
308+
// As above, but without a label.
309+
const existentSSHConfig = `Host beforeconfig
310+
HostName before.config.tld
311+
User before
312+
313+
# --- START CODER VSCODE ---
314+
Host coder-vscode.dev.coder.com--*
315+
ConnectTimeout 0
316+
LogLevel ERROR
317+
ProxyCommand some-command-here
318+
StrictHostKeyChecking no
319+
UserKnownHostsFile /dev/null
320+
# missing END CODER VSCODE ---
321+
322+
Host donotdelete
323+
HostName dont.delete.me
324+
User please
325+
326+
# --- START CODER VSCODE ---
327+
Host coder-vscode.dev.coder.com--*
328+
ConnectTimeout 0
329+
LogLevel ERROR
330+
ProxyCommand some-command-here
331+
StrictHostKeyChecking no
332+
UserKnownHostsFile /dev/null
333+
# --- END CODER VSCODE ---
334+
335+
Host afterconfig
336+
HostName after.config.tld
337+
User after`
338+
339+
const sshConfig = new SSHConfig(sshFilePath, mockFileSystem)
340+
mockFileSystem.readFile.mockResolvedValueOnce(existentSSHConfig)
341+
await sshConfig.load()
342+
343+
// When we try to update the config, it should throw an error.
344+
await expect(
345+
sshConfig.update("", {
346+
Host: "coder-vscode.dev.coder.com--*",
347+
ProxyCommand: "some-command-here",
348+
ConnectTimeout: "0",
349+
StrictHostKeyChecking: "no",
350+
UserKnownHostsFile: "/dev/null",
351+
LogLevel: "ERROR",
352+
}),
353+
).rejects.toThrow(`Malformed config: Unterminated START CODER VSCODE block: Each START block must have an END block.`)
354+
})
355+
307356
it("throws an error if there are more than one sections with the same label", async () => {
308357
const existentSSHConfig = `Host beforeconfig
309358
HostName before.config.tld
@@ -349,7 +398,9 @@ Host afterconfig
349398
UserKnownHostsFile: "/dev/null",
350399
LogLevel: "ERROR",
351400
}),
352-
).rejects.toThrow(`Malformed config: ssh config has 2 dev.coder.com sections, please remove all but one.`)
401+
).rejects.toThrow(
402+
`Malformed config: ssh config has 2 START CODER VSCODE dev.coder.com sections, please remove all but one.`,
403+
)
353404
})
354405

355406
it("correctly handles interspersed blocks with and without label", async () => {

src/sshConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,12 @@ export class SSHConfig {
138138

139139
if (startBlockCount !== endBlockCount) {
140140
throw new SSHConfigBadFormat(
141-
`Malformed config: ssh config has ${startBlockCount} ${label} START comments but ${endBlockCount} ${label} END comments. Each START must have a matching END.`,
141+
`Malformed config: Unterminated START CODER VSCODE ${label ? label + " " : ""}block: Each START block must have an END block.`,
142142
)
143143
}
144144
if (startBlockCount > 1 || endBlockCount > 1) {
145145
throw new SSHConfigBadFormat(
146-
`Malformed config: ssh config has ${startBlockCount} ${label} sections, please remove all but one.`,
146+
`Malformed config: ssh config has ${startBlockCount} START CODER VSCODE ${label ? label + " " : ""}sections, please remove all but one.`,
147147
)
148148
}
149149

0 commit comments

Comments
 (0)