Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement, show available options when a component dir was not found #8593

Merged
merged 4 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/commands/status.e2e.2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/consumer/component/consumer-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <component-id>".
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 <component-id>".`);
this.code = 127;
this.path = path;
if (cause) this.cause = cause;
Expand Down