1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Improve unix shell env sync error logging (#6531)

Signed-off-by: Sebastian Malton <sebastian@malton.name>

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-11-07 11:57:25 -08:00 committed by GitHub
parent b498f12186
commit c00b548d61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -111,25 +111,37 @@ const computeUnixShellEnvironmentInjectable = getInjectable({
const stdout: Buffer[] = []; const stdout: Buffer[] = [];
const stderr: Buffer[] = []; const stderr: Buffer[] = [];
shellProcess.stdout.on("data", b => stdout.push(b)); const getErrorContext = (other: object = {}) => {
shellProcess.stderr.on("data", b => stderr.push(b));
shellProcess.on("error", (err) => resolve({
callWasSuccessful: false,
error: `Failed to spawn ${shellPath}: ${err}`,
}));
shellProcess.on("close", (code, signal) => {
if (code || signal) {
const context = { const context = {
code, ...other,
signal,
stdout: Buffer.concat(stdout).toString("utf-8"), stdout: Buffer.concat(stdout).toString("utf-8"),
stderr: Buffer.concat(stderr).toString("utf-8"), stderr: Buffer.concat(stderr).toString("utf-8"),
}; };
return JSON.stringify(context, null, 4);
};
shellProcess.stdout.on("data", b => stdout.push(b));
shellProcess.stderr.on("data", b => stderr.push(b));
shellProcess.on("error", (error) => {
if (opts.signal.aborted) {
resolve({
callWasSuccessful: false,
error: `timeout: ${getErrorContext()}`,
});
} else {
resolve({
callWasSuccessful: false,
error: `Failed to spawn ${shellPath}: ${getErrorContext({ error })}`,
});
}
});
shellProcess.on("close", (code, signal) => {
if (code || signal) {
return resolve({ return resolve({
callWasSuccessful: false, callWasSuccessful: false,
error: `Shell did not exit sucessfully: ${JSON.stringify(context, null, 4)}`, error: `Shell did not exit sucessfully: ${getErrorContext({ code, signal })}`,
}); });
} }