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

Introduce a temporary but better shape of ExecFileInjectable error

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-10-20 11:27:13 -04:00
parent 6507011145
commit ce8d58b0f4
8 changed files with 23 additions and 31 deletions

View File

@ -3,12 +3,12 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { ExecFileOptions } from "child_process";
import type { ExecFileException, ExecFileOptions } from "child_process";
import { execFile } from "child_process";
import type { AsyncResult } from "../utils/async-result";
export interface ExecFile {
(filePath: string, args: string[], options?: ExecFileOptions): Promise<AsyncResult<string, { stderr: string; error: Error }>>;
(filePath: string, args: string[], options?: ExecFileOptions): Promise<AsyncResult<string, ExecFileException & { stderr: string }>>;
}
const execFileInjectable = getInjectable({
@ -19,10 +19,7 @@ const execFileInjectable = getInjectable({
if (error) {
resolve({
callWasSuccessful: false,
error: {
error,
stderr,
},
error: Object.assign(error, { stderr }),
});
} else {
resolve({

View File

@ -185,10 +185,9 @@ describe("add custom helm repository in preferences", () => {
beforeEach(async () => {
await execFileMock.resolve({
callWasSuccessful: false,
error: {
error: new Error("Some error"),
error: Object.assign(new Error("Some error"), {
stderr: "",
},
}),
});
});

View File

@ -130,10 +130,9 @@ describe("add helm repository from list in preferences", () => {
beforeEach(async () => {
await execFileMock.resolve({
callWasSuccessful: false,
error: {
error: new Error("Some error"),
error: Object.assign(new Error("Some error"), {
stderr: "",
},
}),
});
});

View File

@ -85,10 +85,9 @@ describe("listing active helm repositories in preferences", () => {
beforeEach(async () => {
await execFileMock.resolve({
callWasSuccessful: false,
error: {
error: new Error("some error"),
error: Object.assign(new Error("Some error"), {
stderr: "some-error",
},
}),
});
});
@ -235,10 +234,9 @@ describe("listing active helm repositories in preferences", () => {
beforeEach(async () => {
await execFileMock.resolve({
callWasSuccessful: false,
error: {
error: new Error("Some error"),
error: Object.assign(new Error("Some error"), {
stderr: "Some error",
},
}),
});
});
@ -271,10 +269,9 @@ describe("listing active helm repositories in preferences", () => {
await execFileMock.resolve({
callWasSuccessful: false,
error: {
error: new Error("no repositories found. You must add one before updating"),
error: Object.assign(new Error("no repositories found. You must add one before updating"), {
stderr: "no repositories found. You must add one before updating",
},
}),
});
});
@ -300,10 +297,9 @@ describe("listing active helm repositories in preferences", () => {
beforeEach(async () => {
await execFileMock.resolve({
callWasSuccessful: false,
error: {
error: new Error("Some error"),
error: Object.assign(new Error("Some error"), {
stderr: "Some error",
},
}),
});
});

View File

@ -3,11 +3,12 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { ExecFileException } from "child_process";
import execFileInjectable from "../../../common/fs/exec-file.injectable";
import type { AsyncResult } from "../../../common/utils/async-result";
import helmBinaryPathInjectable from "../helm-binary-path.injectable";
export type ExecHelm = (args: string[]) => Promise<AsyncResult<string, { stderr: string; error: Error }>>;
export type ExecHelm = (args: string[]) => Promise<AsyncResult<string, ExecFileException & { stderr: string }>>;
const execHelmInjectable = getInjectable({
id: "exec-helm",

View File

@ -30,7 +30,7 @@ const callForHelmManifestInjectable = getInjectable({
]);
if (!result.callWasSuccessful) {
return { callWasSuccessful: false, error: result.error.error.message };
return { callWasSuccessful: false, error: result.error.message };
}
return {

View File

@ -65,7 +65,7 @@ const addHelmRepositoryInjectable = getInjectable({
return {
callWasSuccessful: false,
error: result.error.stderr || result.error.error.message,
error: result.error.stderr || result.error.message,
};
};
},

View File

@ -63,7 +63,7 @@ export class ResourceApplier {
return result.response;
}
throw result.error.stderr || result.error.error;
throw result.error.stderr || result.error.message;
}
async create(resource: string): Promise<string> {
@ -102,7 +102,7 @@ export class ResourceApplier {
return result.response;
}
throw result.error.stderr || result.error.error;
throw result.error.stderr || result.error.message;
} finally {
await this.dependencies.deleteFile(fileName);
}
@ -141,11 +141,11 @@ export class ResourceApplier {
return result.response;
}
this.dependencies.logger.error(`[RESOURCE-APPLIER] kubectl errored: ${result.error.error}`);
this.dependencies.logger.error(`[RESOURCE-APPLIER] kubectl errored: ${result.error.message}`);
const splitError = result.error.stderr.split(`.yaml": `);
throw splitError[1] || result.error.error;
throw splitError[1] || result.error.message;
}
protected sanitizeObject(resource: string) {