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

delete invalid objects when running bit reset --never-exported #8100

Merged
merged 2 commits into from
Nov 3, 2023
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 src/scope/exceptions/bit-id-comp-id-err.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { VERSION_CHANGED_BIT_ID_TO_COMP_ID } from '../../constants';
export class BitIdCompIdError extends BitError {
constructor(readonly id: string) {
super(`components in your workspace (e.g. "${id}") were tagged/snapped with older bit version (before v${VERSION_CHANGED_BIT_ID_TO_COMP_ID}), please bit-export with the same bit version.
alternatively, if local (unexported) tags/snaps are not relevant for you anymore, reset them by running "bit reset --never-exported".
alternatively, if local (unexported) tags/snaps/lanes are not relevant for you anymore, reset them by running "bit reset --never-exported".
in case "bit reset" fails with this error, clear your local scope by running "bit init --reset-scope", and then run "bit status"`);
}
}
22 changes: 19 additions & 3 deletions src/scope/objects/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { concurrentIOLimit } from '../../utils/concurrency';
import { createInMemoryCache } from '../../cache/cache-factory';
import { getMaxSizeForObjects, InMemoryCache } from '../../cache/in-memory-cache';
import { Types } from '../object-registrar';
import { Lane, ModelComponent, Symlink } from '../models';
import { Lane, ModelComponent } from '../models';
import { ComponentFsCache } from '../../consumer/component/component-fs-cache';
import { pMapPool } from '../../utils/promise-with-concurrent';

Expand Down Expand Up @@ -207,7 +207,23 @@ export default class Repository {
await pMapPool(
refs,
async (ref) => {
const object = await this.load(ref);
let object: BitObject;
try {
object = await this.load(ref);
} catch (err: any) {
// this is needed temporarily to allow `bit reset --never-exported` to fix the bit-id-comp-id error.
// in a few months, we can remove this condition (around min 2024)
if (
process.argv.includes('--never-exported') &&
(err.constructor.name === 'BitIdCompIdError' || err.constructor.name === 'MissingScope')
) {
logger.debug(`bit-id-comp-id error, moving an object to trash ${ref.toString()}`);
await this.moveOneObjectToTrash(ref);
return;
}
throw err;
}

types.forEach((type) => {
if (
object instanceof type ||
Expand Down Expand Up @@ -309,7 +325,7 @@ export default class Repository {
return scopeIndex;
} catch (err: any) {
if (err.code === 'ENOENT') {
const bitObjects: BitObject[] = await this.list([ModelComponent, Symlink, Lane]);
const bitObjects: BitObject[] = await this.list([ModelComponent, Lane]);
const scopeIndex = ScopeIndex.create(this.scopePath);
const added = scopeIndex.addMany(bitObjects);
if (added) await scopeIndex.write();
Expand Down