Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
Remove unnecessary logging of stderr
Browse files Browse the repository at this point in the history
Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
  • Loading branch information
t1m0thyj committed Mar 15, 2023
1 parent 90d359d commit 53ea3f7
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 28 deletions.
21 changes: 1 addition & 20 deletions packages/utilities/__tests__/ProcessUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

import * as childProcess from "child_process";
import { DaemonRequest, GuiResult, ImperativeConfig, ProcessUtils } from "../../utilities";
import { GuiResult, ImperativeConfig, ProcessUtils } from "../../utilities";

jest.mock("child_process");
jest.mock("opener");
Expand Down Expand Up @@ -343,24 +343,5 @@ describe("ProcessUtils tests", () => {
expect(childProcess.spawnSync).toHaveBeenCalledWith("cat", [filename], undefined);
expect(caughtError.message).toBe(`Command failed: cat ${filename}\n${stderrBuffer.toString()}`);
});

it("logs stderr output to daemon stream", () => {
const stderrBuffer = Buffer.from("Task failed successfully\n");
const streamWriteMock = jest.fn();
jest.spyOn(childProcess, "spawnSync").mockReturnValueOnce({
status: 0,
stderr: stderrBuffer
} as any);
jest.spyOn(ImperativeConfig, "instance", "get").mockReturnValueOnce({
daemonContext: {
stream: { write: streamWriteMock }
}
} as any);
ProcessUtils.execAndCheckOutput("fail");
expect(childProcess.spawnSync).toHaveBeenCalledWith("fail", undefined, undefined);
expect(streamWriteMock).toHaveBeenCalledWith(JSON.stringify({
stderr: stderrBuffer.toString()
}) + DaemonRequest.EOW_DELIMITER);
});
});
});
8 changes: 0 additions & 8 deletions packages/utilities/src/ProcessUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,6 @@ export class ProcessUtils {
// Implementation based on the child_process module
// https://github.com/nodejs/node/blob/main/lib/child_process.js
const result = spawnSync(command, args, options);
if (options?.stdio == null && result.stderr?.length > 0) {
const daemonStream = ImperativeConfig.instance.daemonContext?.stream;
if (daemonStream != null) {
daemonStream.write(DaemonRequest.create({ stderr: result.stderr.toString() }));
} else {
process.stderr.write(result.stderr);
}
}
if (result.error != null) {
throw result.error;
} else if (result.status !== 0) {
Expand Down

0 comments on commit 53ea3f7

Please sign in to comment.