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

replace ShowDoctorError with BitError #7995

Merged
merged 1 commit into from
Oct 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
4 changes: 2 additions & 2 deletions scopes/component/component-writer/component-writer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import fs from 'fs-extra';
import * as path from 'path';
import { BitId, BitIds } from '@teambit/legacy/dist/bit-id';
import ShowDoctorError from '@teambit/legacy/dist/error/show-doctor-error';
import logger from '@teambit/legacy/dist/logger/logger';
import { Scope } from '@teambit/legacy/dist/scope';
import getNodeModulesPathOfComponent from '@teambit/legacy/dist/utils/bit/component-node-modules-path';
Expand All @@ -15,6 +14,7 @@ import Consumer from '@teambit/legacy/dist/consumer/consumer';
import { isHash } from '@teambit/component-version';
import { Ref } from '@teambit/legacy/dist/scope/objects';
import { Workspace } from '@teambit/workspace';
import { BitError } from '@teambit/bit-error';

export type ComponentWriterProps = {
component: Component;
Expand Down Expand Up @@ -98,7 +98,7 @@ export default class ComponentWriter {
async populateComponentsFilesToWrite(): Promise<Component> {
if (this.isolated) throw new Error('for isolation, please use this.populateComponentsFilesToWriteForCapsule()');
if (!this.component.files || !this.component.files.length) {
throw new ShowDoctorError(`Component ${this.component.id.toString()} is invalid as it has no files`);
throw new BitError(`Component ${this.component.id.toString()} is invalid as it has no files`);
}
this.throwForImportingLegacyIntoHarmony();
this.component.dataToPersist = new DataToPersist();
Expand Down
4 changes: 2 additions & 2 deletions scopes/component/snapping/tag-model-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import R from 'ramda';
import { isEmpty } from 'lodash';
import { ReleaseType } from 'semver';
import { v4 } from 'uuid';
import { BitError } from '@teambit/bit-error';
import * as globalConfig from '@teambit/legacy/dist/api/consumer/lib/global-config';
import { Scope } from '@teambit/legacy/dist/scope';
import { BitId, BitIds } from '@teambit/legacy/dist/bit-id';
Expand All @@ -20,7 +21,6 @@ import { linkToNodeModulesByComponents } from '@teambit/workspace.modules.node-m
import ConsumerComponent from '@teambit/legacy/dist/consumer/component/consumer-component';
import Consumer from '@teambit/legacy/dist/consumer/consumer';
import { NewerVersionFound } from '@teambit/legacy/dist/consumer/exceptions';
import ShowDoctorError from '@teambit/legacy/dist/error/show-doctor-error';
import { Component } from '@teambit/component';
import deleteComponentsFiles from '@teambit/legacy/dist/consumer/component-ops/delete-component-files';
import logger from '@teambit/legacy/dist/logger/logger';
Expand Down Expand Up @@ -262,7 +262,7 @@ export async function tagModelComponent({
if (component.componentFromModel) {
// otherwise it's a new component, so this check is irrelevant
const modelComponent = await legacyScope.getModelComponentIfExist(component.id);
if (!modelComponent) throw new ShowDoctorError(`component ${component.id} was not found in the model`);
if (!modelComponent) throw new BitError(`component ${component.id} was not found in the model`);
if (!modelComponent.listVersions().length) return null; // no versions yet, no issues.
const latest = modelComponent.getHeadRegardlessOfLaneAsTagOrHash();
if (latest !== component.version) {
Expand Down
2 changes: 1 addition & 1 deletion scopes/harmony/api-server/cli.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class CLIRoute implements Route {
.map((key) => `--${key}`)
.join(' ');
this.logger.console(
`started a new ${outputMethod} command: ${req.params.cmd} ${(args || []).join(' ')} ${optsToString}`
`[*] started a new ${outputMethod} command: ${req.params.cmd} ${(args || []).join(' ')} ${optsToString}`
);
const optionsAsCamelCase = Object.keys(options || {}).reduce((acc, key) => {
const camelCaseKey = camelCase(key);
Expand Down
2 changes: 1 addition & 1 deletion scopes/harmony/api-server/ide.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class IDERoute implements Route {
}
const body = req.body;
const { args } = body;
this.logger.console(`started a new api-IDE call: ${req.params.method}, total: ${args?.length || 0} args`);
this.logger.console(`[*] started a new api-IDE call: ${req.params.method}, total: ${args?.length || 0} args`);
const startTask = process.hrtime();
const result = await this.apiForIDE[req.params.method](...args);
const duration = prettyTime(process.hrtime(startTask));
Expand Down
3 changes: 1 addition & 2 deletions scopes/scope/importer/import-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { Consumer } from '@teambit/legacy/dist/consumer';
import loader from '@teambit/legacy/dist/cli/loader';
import { BEFORE_IMPORT_ACTION } from '@teambit/legacy/dist/cli/loader/loader-messages';
import GeneralError from '@teambit/legacy/dist/error/general-error';
import ShowDoctorError from '@teambit/legacy/dist/error/show-doctor-error';
import logger from '@teambit/legacy/dist/logger/logger';
import { Scope } from '@teambit/legacy/dist/scope';
import { Lane, ModelComponent, Version } from '@teambit/legacy/dist/scope/models';
Expand Down Expand Up @@ -500,7 +499,7 @@ bit import ${idsFromRemote.map((id) => id.toStringWithoutVersion()).join(' ')}`)
);
}
const modelComponent = await this.consumer.scope.getModelComponentIfExist(id);
if (!modelComponent) throw new ShowDoctorError(`imported component ${idStr} was not found in the model`);
if (!modelComponent) throw new BitError(`imported component ${idStr} was not found in the model`);
const afterImportVersions = modelComponent.listVersions();
const versionDifference: string[] = R.difference(afterImportVersions, beforeImportVersions);
const getStatus = (): ImportStatus => {
Expand Down
11 changes: 4 additions & 7 deletions src/consumer/bit-map/bit-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
VERSION_DELIMITER,
BITMAP_PREFIX_MESSAGE,
} from '../../constants';
import ShowDoctorError from '../../error/show-doctor-error';
import logger from '../../logger/logger';
import { isDir, pathJoinLinux, pathNormalizeToLinux, sortObject } from '../../utils';
import { PathLinux, PathLinuxRelative, PathOsBased, PathOsBasedAbsolute, PathOsBasedRelative } from '../../utils/path';
Expand Down Expand Up @@ -88,15 +87,13 @@ export default class BitMap {
setComponent(bitId: BitId, componentMap: ComponentMap) {
const id = bitId.toString();
if (!bitId.hasVersion() && bitId.scope) {
throw new ShowDoctorError(
`invalid bitmap id ${id}, a component must have a version when a scope-name is included`
);
throw new BitError(`invalid bitmap id ${id}, a component must have a version when a scope-name is included`);
}
if (!isFeatureEnabled(ALLOW_SAME_NAME)) {
// make sure there are no duplications (same name)
const similarIds = this.findSimilarIds(bitId, true);
if (similarIds.length) {
throw new ShowDoctorError(`your id ${id} is duplicated with ${similarIds.toString()}`);
throw new BitError(`your id ${id} is duplicated with ${similarIds.toString()}`);
}
}
componentMap.id = bitId;
Expand Down Expand Up @@ -701,7 +698,7 @@ export default class BitMap {
const componentIdStr = componentId.toString();
const componentMap = this.getComponentIfExist(componentId);
if (!componentMap) {
throw new ShowDoctorError(`unable to add files to a non-exist component ${componentIdStr}`);
throw new BitError(`unable to add files to a non-exist component ${componentIdStr}`);
}
logger.info(`bit.map: updating an exiting component ${componentIdStr}`);
componentMap.files = files;
Expand Down Expand Up @@ -890,7 +887,7 @@ export default class BitMap {
const errorMsg = isPathDir
? `directory ${from} is not a tracked component`
: `the file ${existingPath} is untracked`;
throw new ShowDoctorError(errorMsg);
throw new BitError(errorMsg);
}

this.markAsChanged();
Expand Down
6 changes: 3 additions & 3 deletions src/consumer/component-ops/component-status-loader.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import mapSeries from 'p-map-series';
import { BitError } from '@teambit/bit-error';
import { Consumer } from '..';
import { BitId, BitIds } from '../../bit-id';
import { LATEST } from '../../constants';
import ShowDoctorError from '../../error/show-doctor-error';
import { ModelComponent } from '../../scope/models';
import { MissingBitMapComponent } from '../bit-map/exceptions';
import ComponentsPendingImport from '../component-ops/exceptions/components-pending-import';
Expand Down Expand Up @@ -105,10 +105,10 @@ export class ComponentStatusLoader {
// const versionFromModel = await componentFromModel.loadVersion(versionFromFs, this.consumer.scope.objects);
// it looks like it's exactly the same code but it's not working from some reason
const versionRef = componentFromModel.getRef(versionFromFs);
if (!versionRef) throw new ShowDoctorError(`version ${versionFromFs} was not found in ${idStr}`);
if (!versionRef) throw new BitError(`version ${versionFromFs} was not found in ${idStr}`);
const versionFromModel = await this.consumer.scope.getObject(versionRef.hash);
if (!versionFromModel) {
throw new ShowDoctorError(`failed loading version ${versionFromFs} of ${idStr} from the scope`);
throw new BitError(`failed loading version ${versionFromFs} of ${idStr} from the scope`);
}
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
status.modified = await this.consumer.isComponentModified(versionFromModel, componentFromFileSystem);
Expand Down
4 changes: 2 additions & 2 deletions src/consumer/component-ops/components-diff.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import chalk from 'chalk';
import R from 'ramda';
import { BitError } from '@teambit/bit-error';
import { Consumer } from '..';
import { BitId } from '../../bit-id';
import GeneralError from '../../error/general-error';
import ShowDoctorError from '../../error/show-doctor-error';
import { Scope } from '../../scope';
import { ModelComponent, Version } from '../../scope/models';
import diffFiles from '../../utils/diff-files';
Expand Down Expand Up @@ -48,7 +48,7 @@ export default async function componentsDiff(
): Promise<DiffResults[]> {
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
const { components } = await consumer.loadComponents(ids);
if (!components) throw new ShowDoctorError('failed loading the components');
if (!components) throw new BitError('failed loading the components');

// try to resolve ids scope of by components array
const idsWithScope = ids.map((id) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import fs from 'fs-extra';
import R from 'ramda';
import semver from 'semver';
import { isSnap } from '@teambit/component-version';
import { BitError } from '@teambit/bit-error';
import { uniq, isEmpty, union, cloneDeep } from 'lodash';
import { IssuesList, IssuesClasses } from '@teambit/component-issues';
import { Dependency } from '..';
import { BitId, BitIds } from '../../../../bit-id';
import { DEFAULT_DIST_DIRNAME, DEPENDENCIES_FIELDS, MANUALLY_REMOVE_DEPENDENCY } from '../../../../constants';
import Consumer from '../../../../consumer/consumer';
import GeneralError from '../../../../error/general-error';
import ShowDoctorError from '../../../../error/show-doctor-error';
import logger from '../../../../logger/logger';
import { getExt, pathNormalizeToLinux, pathRelativeLinux } from '../../../../utils';
import { PathLinux, PathLinuxRelative, PathOsBased } from '../../../../utils/path';
Expand Down Expand Up @@ -444,7 +444,7 @@ export default class DependencyResolver {
.getAllDependencies()
.find((dep) => dep.id.isEqualWithoutVersion(componentId));
if (!dependency) {
throw new ShowDoctorError( // $FlowFixMe
throw new BitError(
`the auto-generated file ${depFile} should be connected to ${componentId}, however, it's not part of the model dependencies of ${this.componentFromModel.id}`
);
}
Expand All @@ -453,7 +453,7 @@ export default class DependencyResolver {
(r) => r.sourceRelativePath === depFile
);
if (!relativePath) {
throw new ShowDoctorError(
throw new BitError(
`unable to find ${relativePath} path in the dependencies relativePaths of ${this.componentFromModel.id}`
);
}
Expand Down
5 changes: 2 additions & 3 deletions src/consumer/component/sources/artifact-files.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import fs from 'fs-extra';
import path from 'path';
import R from 'ramda';
import { BitError } from '@teambit/bit-error';
import { BitId } from '../../../bit-id';
import ShowDoctorError from '../../../error/show-doctor-error';
import logger from '../../../logger/logger';
import { Scope } from '../../../scope';
import { Lane, Source } from '../../../scope/models';
import { Ref } from '../../../scope/objects';
import { pathNormalizeToLinux } from '../../../utils';
import { ExtensionDataList } from '../../config';
import Component from '../consumer-component';

import { ArtifactVinyl } from './artifact';

export type ArtifactRef = { relativePath: string; ref: Ref; url?: string };
Expand Down Expand Up @@ -146,7 +145,7 @@ export class ArtifactFiles {
}
const getOneArtifact = async (artifact: ArtifactRef) => {
const content = (await artifact.ref.load(scope.objects)) as Source;
if (!content) throw new ShowDoctorError(`failed loading file ${artifact.relativePath} from the model`);
if (!content) throw new BitError(`failed loading file ${artifact.relativePath} from the model`);
return new ArtifactVinyl({
base: '.',
path: artifact.relativePath,
Expand Down
4 changes: 2 additions & 2 deletions src/consumer/config/component-config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import mapSeries from 'p-map-series';
import { pickBy } from 'lodash';
import R from 'ramda';
import { BitError } from '@teambit/bit-error';
import { BitId } from '../../bit-id';
import { DEFAULT_REGISTRY_DOMAIN_PREFIX } from '../../constants';
import ShowDoctorError from '../../error/show-doctor-error';
import logger from '../../logger/logger';
import Component from '../component/consumer-component';
import PackageJsonFile from '../component/package-json-file';
Expand Down Expand Up @@ -64,7 +64,7 @@ export default class ComponentConfig extends AbstractConfig {

validate(bitJsonPath: string) {
if (this.extensions && typeof this.extensions !== 'object') {
throw new ShowDoctorError(
throw new BitError(
`bit.json at "${bitJsonPath}" is invalid, re-import the component with "--conf" flag to recreate it`
);
}
Expand Down
10 changes: 0 additions & 10 deletions src/error/show-doctor-error.ts

This file was deleted.

5 changes: 2 additions & 3 deletions src/npm-client/npm-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import mapSeries from 'p-map-series';
import * as path from 'path';
import R, { is, isNil, join, map, toPairs } from 'ramda';
import semver from 'semver';

import { BitError } from '@teambit/bit-error';
import { Analytics } from '../analytics/analytics';
import { BASE_DOCS_DOMAIN, DEFAULT_PACKAGE_MANAGER, IS_WINDOWS } from '../constants';
import { PackageManagerClients } from '../consumer/config/legacy-workspace-config-interface';
import ShowDoctorError from '../error/show-doctor-error';
import logger from '../logger/logger';
import { PathOsBased } from '../utils/path';

Expand Down Expand Up @@ -150,7 +149,7 @@ const _installInOneDirectory = ({
.catch((err) => {
let stderr = `failed running ${packageManager} install at ${cwd} ${argsString} \n`;
stderr += verbose ? err.stderr : stripNonNpmErrors(err.stderr, packageManager);
throw new ShowDoctorError(
throw new BitError(
`${stderr}\n\n${chalk.yellow(
`see troubleshooting at https://${BASE_DOCS_DOMAIN}/dependencies/dependency-installation`
)}`
Expand Down
5 changes: 2 additions & 3 deletions src/scope/component-ops/scope-components-importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { Scope } from '..';
import { BitId, BitIds } from '../../bit-id';
import ConsumerComponent from '../../consumer/component';
import GeneralError from '../../error/general-error';
import ShowDoctorError from '../../error/show-doctor-error';
import enrichContextFromGlobal from '../../hooks/utils/enrich-context-from-global';
import logger from '../../logger/logger';
import { Remotes } from '../../remotes';
Expand Down Expand Up @@ -645,7 +644,7 @@ export default class ScopeComponentsImporter {
if (version) return version;
if (id.isLocal(this.scope.name)) {
// it should have been fetched locally, since it wasn't found, this is an error
throw new ShowDoctorError(
throw new BitError(
`Version ${versionComp.version} of ${id.toString()} was not found in scope ${this.scope.name}`
);
}
Expand Down Expand Up @@ -997,7 +996,7 @@ export default class ScopeComponentsImporter {
const version = await this.getVersionFromComponentDef(component, id);
if (!version) {
// should have been fetched before by getExternalMany(). probably doesn't exist on the remote.
throw new ShowDoctorError(`Version ${versionComp.version} of ${component.id().toString()} was not found`);
throw new BitError(`Version ${versionComp.version} of ${component.id().toString()} was not found`);
}
return new VersionDependencies(versionComp, [], version);
});
Expand Down
8 changes: 3 additions & 5 deletions src/scope/models/model-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { forEach, isEmpty, pickBy, mapValues } from 'lodash';
import { Mutex } from 'async-mutex';
import * as semver from 'semver';
import { versionParser, isHash, isTag } from '@teambit/component-version';
import { BitError } from '@teambit/bit-error';
import { LaneId, DEFAULT_LANE } from '@teambit/lane-id';
import pMapSeries from 'p-map-series';
import { LegacyComponentLog } from '@teambit/legacy-component-log';
Expand All @@ -18,7 +19,6 @@ import ConsumerComponent from '../../consumer/component';
import { License, SourceFile } from '../../consumer/component/sources';
import ComponentOverrides from '../../consumer/config/component-overrides';
import GeneralError from '../../error/general-error';
import ShowDoctorError from '../../error/show-doctor-error';
import ValidationError from '../../error/validation-error';
import logger from '../../logger/logger';
import { getStringifyArgs } from '../../utils';
Expand Down Expand Up @@ -857,7 +857,7 @@ consider using --ignore-missing-artifacts flag if you're sure the artifacts are
throw new NoHeadNoVersion(this.id());
}
if (isTag(versionNum) && !this.hasTagIncludeOrphaned(versionNum)) {
throw new ShowDoctorError(
throw new BitError(
`the version ${versionNum} of "${this.id()}" does not exist in ${this.listVersionsIncludeOrphaned().join(
'\n'
)}, versions array.`
Expand Down Expand Up @@ -936,9 +936,7 @@ consider using --ignore-missing-artifacts flag if you're sure the artifacts are
const loadP = file.file.load(repository);
const content: Source = await loadP;
if (!content)
throw new ShowDoctorError(
`failed loading file ${file.relativePath} from the model of ${this.id()}@${versionStr}`
);
throw new BitError(`failed loading file ${file.relativePath} from the model of ${this.id()}@${versionStr}`);
return new ClassName({ base: '.', path: file.relativePath, contents: content.contents, test: file.test });
};
const filesP = version.files ? Promise.all(version.files.map(loadFileInstance(SourceFile))) : null;
Expand Down
5 changes: 2 additions & 3 deletions src/scope/objects/objects-readable-generator.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pMapSeries from 'p-map-series';
import { BitError } from '@teambit/bit-error';
import { Readable } from 'stream';
import { Ref, Repository } from '.';
import { Scope } from '..';
import ShowDoctorError from '../../error/show-doctor-error';
import logger from '../../logger/logger';
import { getAllVersionHashesMemoized } from '../component-ops/traverse-versions';
import { HashMismatch } from '../exceptions';
Expand Down Expand Up @@ -108,8 +108,7 @@ export class ObjectsReadableGenerator {
const { component, collectParents, collectArtifacts, collectParentsUntil, includeVersionHistory } =
componentWithOptions;
const version = await component.loadVersion(componentWithOptions.version, this.repo, false);
if (!version)
throw new ShowDoctorError(`failed loading version ${componentWithOptions.version} of ${component.id()}`);
if (!version) throw new BitError(`failed loading version ${componentWithOptions.version} of ${component.id()}`);
if (collectParentsUntil && version.hash().isEqual(collectParentsUntil)) {
return;
}
Expand Down
Loading