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

fix, suggest running "bit init" when local-scope is empty #8967

Merged
merged 1 commit into from
Jun 21, 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: 0 additions & 2 deletions src/cli/default-error-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import {
OutdatedIndexJson,
ParentNotFound,
ScopeJsonNotFound,
ScopeNotFound,
VersionAlreadyExists,
} from '../scope/exceptions';
import {
Expand Down Expand Up @@ -122,7 +121,6 @@ ${err.message ? `server responded with: "${err.message}"` : ''}`,
To rebuild the file, please run ${chalk.bold('bit init --reset')}.
Original Error: ${err.message}`,
],
[ScopeNotFound, (err) => `error: scope not found at ${chalk.bold(err.scopePath)}`],
[
ScopeJsonNotFound,
(err) =>
Expand Down
9 changes: 7 additions & 2 deletions src/consumer/consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import logger from '../logger/logger';
import { Scope } from '../scope';
import { getAutoTagPending } from '../scope/component-ops/auto-tag';
import { ComponentNotFound } from '../scope/exceptions';
import { ComponentNotFound, ScopeNotFound } from '../scope/exceptions';
import { Lane, ModelComponent, Version } from '../scope/models';
// import { generateRandomStr } from '@teambit/toolbox.string.random';
import { sortObjectByKeys } from '@teambit/toolbox.object.sorter';
Expand Down Expand Up @@ -488,7 +488,12 @@ export default class Consumer {
`fatal: unable to load the workspace. workspace.jsonc or .bitmap or local-scope are missing. run "bit init" to generate the missing files`
);
}
const scope = await Scope.load(consumerInfo.path);
const scope = await Scope.load(consumerInfo.path).catch((err) => {
if (err instanceof ScopeNotFound) {
throw new BitError(`${err.message}\nplease run "bit init" to re-initialize the local-scope`);
}
throw err;
});
const config = await WorkspaceConfig.loadIfExist(consumerInfo.path, scope.path);
const consumer = new Consumer({
projectPath: consumerInfo.path,
Expand Down
11 changes: 5 additions & 6 deletions src/scope/exceptions/scope-not-found.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import AbstractError from '../../error/abstract-error';
import { BitError } from '@teambit/bit-error';
import chalk from 'chalk';

export default class ScopeNotFound extends AbstractError {
scopePath: string;
constructor(scopePath: string) {
super();
this.scopePath = scopePath;
export default class ScopeNotFound extends BitError {
constructor(public scopePath: string) {
super(`error: scope not found at ${chalk.bold(scopePath)}`);
}
}