From d5471e5dbe1f6eef7507087ef517eda3e4f659a3 Mon Sep 17 00:00:00 2001 From: David First Date: Wed, 28 Feb 2024 15:16:59 -0500 Subject: [PATCH 1/2] improvement, show available options when a component dir was not found --- src/consumer/component/consumer-component.ts | 2 +- .../component/exceptions/component-not-found-in-path.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/consumer/component/consumer-component.ts b/src/consumer/component/consumer-component.ts index 070c669ae1f9..ecaa3fea30ac 100644 --- a/src/consumer/component/consumer-component.ts +++ b/src/consumer/component/consumer-component.ts @@ -521,7 +521,7 @@ export default class Component { } const deprecated = componentFromModel ? componentFromModel.deprecated : false; const compDirAbs = path.join(consumer.getPath(), componentMap.getComponentDir()); - if (!fs.existsSync(compDirAbs)) throw new ComponentNotFoundInPath(compDirAbs); + if (!fs.existsSync(compDirAbs)) throw new ComponentNotFoundInPath(componentMap.getComponentDir()); // Load the base entry from the root dir in map file in case it was imported using -path // Or created using bit create so we don't want all the path but only the relative one diff --git a/src/consumer/component/exceptions/component-not-found-in-path.ts b/src/consumer/component/exceptions/component-not-found-in-path.ts index 7e46742fc698..b33e7b57ea81 100644 --- a/src/consumer/component/exceptions/component-not-found-in-path.ts +++ b/src/consumer/component/exceptions/component-not-found-in-path.ts @@ -6,7 +6,12 @@ export default class ComponentNotFoundInPath extends BitError { code: number; constructor(path: string, cause?: Error) { - super(`error: component in path "${chalk.bold(path)}" was not found`); + super(`error: component in path "${chalk.bold( + path + )}" was not found, the following options are available depending on the situation: +1. if the component directory was deleted by mistake, you can restore it by running "bit checkout reset ". +2. if the component-dir was renamed, you can use "bit move" to move it to the new location. +3. if the component directory was deleted deliberately, you can remove it from the workspace by running "bit remove ".`); this.code = 127; this.path = path; if (cause) this.cause = cause; From 1175fcee9c5a73eaa8c65aebbe8195ceebde8d67 Mon Sep 17 00:00:00 2001 From: David First Date: Wed, 28 Feb 2024 17:02:24 -0500 Subject: [PATCH 2/2] fix tests --- e2e/commands/status.e2e.2.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/commands/status.e2e.2.ts b/e2e/commands/status.e2e.2.ts index 41914bb3f3fe..765f0a24ab17 100644 --- a/e2e/commands/status.e2e.2.ts +++ b/e2e/commands/status.e2e.2.ts @@ -382,7 +382,7 @@ describe('bit status command', function () { describe('running bit diff', () => { it('should throw an exception ComponentNotFoundInPath', () => { const diffFunc = () => helper.command.diff('bar/foo'); - const error = new ComponentNotFoundInPath(path.join(helper.scopes.localPath, 'bar')); + const error = new ComponentNotFoundInPath('bar'); helper.general.expectToThrow(diffFunc, error); }); });