mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Capture and log stderr while computing unix shell env on failure
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
487079b61f
commit
35b7c2c062
@ -6,7 +6,7 @@
|
||||
import type { AsyncResult } from "../../../common/utils/async-result";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import isWindowsInjectable from "../../../common/vars/is-windows.injectable";
|
||||
import { disposer } from "../../../common/utils";
|
||||
import { disposer, hasTypedProperty, isString } from "../../../common/utils";
|
||||
import computeUnixShellEnvironmentInjectable from "./compute-unix-shell-environment.injectable";
|
||||
|
||||
export type EnvironmentVariables = Partial<Record<string, string>>;
|
||||
@ -47,6 +47,13 @@ const computeShellEnvironmentInjectable = getInjectable({
|
||||
};
|
||||
}
|
||||
|
||||
if (error && hasTypedProperty(error, "stderr", isString)) {
|
||||
return {
|
||||
callWasSuccessful: false,
|
||||
error: `${error}:\n${error.stderr}`,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
callWasSuccessful: false,
|
||||
error: String(error),
|
||||
|
||||
@ -64,15 +64,19 @@ const computeUnixShellEnvironmentInjectable = getInjectable({
|
||||
env,
|
||||
});
|
||||
const stdout: Buffer[] = [];
|
||||
const stderr: Buffer[] = [];
|
||||
|
||||
opts.signal?.addEventListener("abort", () => shellProcess.kill());
|
||||
|
||||
shellProcess.stdout.on("data", b => stdout.push(b));
|
||||
shellProcess.stderr.on("data", b => stderr.push(b));
|
||||
|
||||
shellProcess.on("error", (err) => reject(err));
|
||||
shellProcess.on("close", (code, signal) => {
|
||||
if (code || signal) {
|
||||
return reject(new Error(`Unexpected return code from spawned shell (code: ${code}, signal: ${signal})`));
|
||||
return reject(Object.assign(new Error(`Unexpected return code from spawned shellPath=${shellPath} (code: ${code}, signal: ${signal})`), {
|
||||
stderr: Buffer.concat(stderr).toString("utf-8"),
|
||||
}));
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user