Skip to content

Commit 9a04336

Browse files
committed
Review comments
1 parent f297fe3 commit 9a04336

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/core/cliExec.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ export interface CliEnv {
1919

2020
const execFileAsync = promisify(execFile);
2121

22-
// util.promisify types are dynamic so there is no concrete type we can import
23-
// and we have to make our own.
24-
type ExecException = ExecFileException & { stdout?: string; stderr?: string };
22+
function isExecFileException(error: unknown): error is ExecFileException {
23+
return error instanceof Error && "code" in error;
24+
}
2525

2626
/** Prefer stderr over the default message which includes the full command line. */
2727
function cliError(error: unknown): Error {
28-
const stderr = (error as ExecException)?.stderr?.trim();
29-
if (stderr) {
30-
return new Error(stderr, { cause: error });
28+
if (isExecFileException(error)) {
29+
const stderr = error.stderr?.trim();
30+
if (stderr) {
31+
return new Error(stderr, { cause: error });
32+
}
3133
}
3234
return toError(error);
3335
}
@@ -55,7 +57,10 @@ export async function version(binPath: string): Promise<string> {
5557
stdout = result.stdout;
5658
} catch (error) {
5759
// It could be an old version without support for --output.
58-
if ((error as ExecException)?.stderr?.includes("unknown flag: --output")) {
60+
if (
61+
isExecFileException(error) &&
62+
error.stderr?.includes("unknown flag: --output")
63+
) {
5964
const result = await execFileAsync(binPath, ["version"]);
6065
if (result.stdout?.startsWith("Coder")) {
6166
const v = result.stdout.split(" ")[1]?.trim();

0 commit comments

Comments
 (0)