Use type of 'string | Buffer'
This commit is contained in:
@@ -19,7 +19,6 @@ import type { CliConfig } from "../config";
|
||||
import type { DistributionProvider } from "./distribution";
|
||||
import { FindDistributionResultKind } from "./distribution";
|
||||
import {
|
||||
asString,
|
||||
assertNever,
|
||||
getErrorMessage,
|
||||
getErrorStack,
|
||||
@@ -1606,8 +1605,8 @@ export function spawnServer(
|
||||
command: string[],
|
||||
commandArgs: string[],
|
||||
logger: Logger,
|
||||
stderrListener: (data: unknown) => void,
|
||||
stdoutListener?: (data: unknown) => void,
|
||||
stderrListener: (data: string | Buffer) => void,
|
||||
stdoutListener?: (data: string | Buffer) => void,
|
||||
progressReporter?: ProgressReporter,
|
||||
): ChildProcessWithoutNullStreams {
|
||||
// Enable verbose logging.
|
||||
@@ -1627,7 +1626,7 @@ export function spawnServer(
|
||||
);
|
||||
}
|
||||
|
||||
let lastStdout: unknown = undefined;
|
||||
let lastStdout: string | Buffer | undefined = undefined;
|
||||
child.stdout!.on("data", (data) => {
|
||||
lastStdout = data;
|
||||
});
|
||||
@@ -1644,7 +1643,7 @@ export function spawnServer(
|
||||
// If the process exited abnormally, log the last stdout message,
|
||||
// It may be from the jvm.
|
||||
if (code !== 0 && lastStdout !== undefined) {
|
||||
void logger.log(`Last stdout was "${asString(lastStdout)}"`);
|
||||
void logger.log(`Last stdout was "${lastStdout.toString()}"`);
|
||||
}
|
||||
});
|
||||
child.stderr!.on("data", stderrListener);
|
||||
|
||||
@@ -68,20 +68,6 @@ export function asError(e: unknown): Error {
|
||||
return e instanceof Error ? e : new Error(String(e));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a unknown value to a string, using `toString` if possible,
|
||||
* or returning the human-readable strings "null" or "undefined".
|
||||
*/
|
||||
export function asString(x: unknown): string {
|
||||
if (x === null) {
|
||||
return "null";
|
||||
} else if (x === undefined) {
|
||||
return "undefined";
|
||||
} else {
|
||||
return x.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get error message when the error may have come from a method from the `child_process` module.
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,6 @@ import { LanguageClient, NotificationType } from "vscode-languageclient/node";
|
||||
import { shouldDebugLanguageServer, spawnServer } from "../codeql-cli/cli";
|
||||
import type { QueryServerConfig } from "../config";
|
||||
import { languageServerLogger } from "../common/logging/vscode";
|
||||
import { asString } from "../common/helpers-pure";
|
||||
|
||||
/**
|
||||
* Managing the language client and corresponding server process for CodeQL.
|
||||
@@ -75,9 +74,9 @@ async function spawnLanguageServer(
|
||||
args,
|
||||
languageServerLogger,
|
||||
(data) =>
|
||||
languageServerLogger.log(asString(data), { trailingNewline: false }),
|
||||
languageServerLogger.log(data.toString(), { trailingNewline: false }),
|
||||
(data) =>
|
||||
languageServerLogger.log(asString(data), { trailingNewline: false }),
|
||||
languageServerLogger.log(data.toString(), { trailingNewline: false }),
|
||||
progressReporter,
|
||||
);
|
||||
return { writer: child.stdin!, reader: child.stdout! };
|
||||
|
||||
@@ -18,7 +18,6 @@ import type { ProgressCallback, ProgressTask } from "../common/vscode/progress";
|
||||
import { withProgress } from "../common/vscode/progress";
|
||||
import { ServerProcess } from "./server-process";
|
||||
import type { App } from "../common/app";
|
||||
import { asString } from "../common/helpers-pure";
|
||||
|
||||
type ServerOpts = {
|
||||
logger: Logger;
|
||||
@@ -215,7 +214,7 @@ export class QueryServerClient extends DisposableObject {
|
||||
args,
|
||||
this.logger,
|
||||
(data) =>
|
||||
this.activeQueryLogger.log(asString(data), {
|
||||
this.activeQueryLogger.log(data.toString(), {
|
||||
trailingNewline: false,
|
||||
}),
|
||||
undefined, // no listener for stdout
|
||||
|
||||
Reference in New Issue
Block a user