Skip to content

Commit 58a0619

Browse files
Use type of 'string | Buffer'
1 parent 388f429 commit 58a0619

File tree

4 files changed

+7
-24
lines changed

4 files changed

+7
-24
lines changed

extensions/ql-vscode/src/codeql-cli/cli.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import type { CliConfig } from "../config";
1919
import type { DistributionProvider } from "./distribution";
2020
import { FindDistributionResultKind } from "./distribution";
2121
import {
22-
asString,
2322
assertNever,
2423
getErrorMessage,
2524
getErrorStack,
@@ -1606,8 +1605,8 @@ export function spawnServer(
16061605
command: string[],
16071606
commandArgs: string[],
16081607
logger: Logger,
1609-
stderrListener: (data: unknown) => void,
1610-
stdoutListener?: (data: unknown) => void,
1608+
stderrListener: (data: string | Buffer) => void,
1609+
stdoutListener?: (data: string | Buffer) => void,
16111610
progressReporter?: ProgressReporter,
16121611
): ChildProcessWithoutNullStreams {
16131612
// Enable verbose logging.
@@ -1627,7 +1626,7 @@ export function spawnServer(
16271626
);
16281627
}
16291628

1630-
let lastStdout: unknown = undefined;
1629+
let lastStdout: string | Buffer | undefined = undefined;
16311630
child.stdout!.on("data", (data) => {
16321631
lastStdout = data;
16331632
});
@@ -1644,7 +1643,7 @@ export function spawnServer(
16441643
// If the process exited abnormally, log the last stdout message,
16451644
// It may be from the jvm.
16461645
if (code !== 0 && lastStdout !== undefined) {
1647-
void logger.log(`Last stdout was "${asString(lastStdout)}"`);
1646+
void logger.log(`Last stdout was "${lastStdout.toString()}"`);
16481647
}
16491648
});
16501649
child.stderr!.on("data", stderrListener);

extensions/ql-vscode/src/common/helpers-pure.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,6 @@ export function asError(e: unknown): Error {
6868
return e instanceof Error ? e : new Error(String(e));
6969
}
7070

71-
/**
72-
* Converts a unknown value to a string, using `toString` if possible,
73-
* or returning the human-readable strings "null" or "undefined".
74-
*/
75-
export function asString(x: unknown): string {
76-
if (x === null) {
77-
return "null";
78-
} else if (x === undefined) {
79-
return "undefined";
80-
} else {
81-
return x.toString();
82-
}
83-
}
84-
8571
/**
8672
* Get error message when the error may have come from a method from the `child_process` module.
8773
*/

extensions/ql-vscode/src/language-support/language-client.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { LanguageClient, NotificationType } from "vscode-languageclient/node";
55
import { shouldDebugLanguageServer, spawnServer } from "../codeql-cli/cli";
66
import type { QueryServerConfig } from "../config";
77
import { languageServerLogger } from "../common/logging/vscode";
8-
import { asString } from "../common/helpers-pure";
98

109
/**
1110
* Managing the language client and corresponding server process for CodeQL.
@@ -75,9 +74,9 @@ async function spawnLanguageServer(
7574
args,
7675
languageServerLogger,
7776
(data) =>
78-
languageServerLogger.log(asString(data), { trailingNewline: false }),
77+
languageServerLogger.log(data.toString(), { trailingNewline: false }),
7978
(data) =>
80-
languageServerLogger.log(asString(data), { trailingNewline: false }),
79+
languageServerLogger.log(data.toString(), { trailingNewline: false }),
8180
progressReporter,
8281
);
8382
return { writer: child.stdin!, reader: child.stdout! };

extensions/ql-vscode/src/query-server/query-server-client.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import type { ProgressCallback, ProgressTask } from "../common/vscode/progress";
1818
import { withProgress } from "../common/vscode/progress";
1919
import { ServerProcess } from "./server-process";
2020
import type { App } from "../common/app";
21-
import { asString } from "../common/helpers-pure";
2221

2322
type ServerOpts = {
2423
logger: Logger;
@@ -215,7 +214,7 @@ export class QueryServerClient extends DisposableObject {
215214
args,
216215
this.logger,
217216
(data) =>
218-
this.activeQueryLogger.log(asString(data), {
217+
this.activeQueryLogger.log(data.toString(), {
219218
trailingNewline: false,
220219
}),
221220
undefined, // no listener for stdout

0 commit comments

Comments
 (0)