diff --git a/src/modules/package-downloader.ts b/src/modules/package-downloader.ts index 31f40f0..aec003c 100644 --- a/src/modules/package-downloader.ts +++ b/src/modules/package-downloader.ts @@ -26,8 +26,11 @@ export class PackageDownloader { this.packageConfig = packageConfig; } - private async _cloneRepository(packageDir: string, cloneOpts: string[]): Promise { - await this.git.clone(this.packageConfig.getPackageRepo(), packageDir, cloneOpts); + private async _cloneRepository(packageDir: string, cloneOpts: string[], verbose?: boolean): Promise { + const response = await this.git.clone(this.packageConfig.getPackageRepo(), packageDir, cloneOpts); + if (verbose) { + console.log(`Clone response: ${response}`); + } } private async _updateRepository(checkRepoAction: CheckRepoActions, verbose: boolean): Promise { @@ -49,7 +52,12 @@ export class PackageDownloader { await this.git.checkout(branchOrTag); } - private async _checkForValidRepo(packageDir: string, cloneOpts: string[], checkRepoAction: CheckRepoActions): Promise { + private async _checkForValidRepo( + packageDir: string, + cloneOpts: string[], + checkRepoAction: CheckRepoActions, + verbose?: boolean, + ): Promise { let directoryExists = CliFileSystem.existsSync(packageDir); if (directoryExists && !(await this.isValidRepo(packageDir, checkRepoAction))) { CliFileSystem.removeSync(packageDir); @@ -57,7 +65,22 @@ export class PackageDownloader { } if (!directoryExists) { - await this._cloneRepository(packageDir, cloneOpts); + try { + // simple-git typically throws an error if clone fails + // but not all errors reult in an exception, for instance blocked clone due to rate limitation + // does not result in an exception + await this._cloneRepository(packageDir, cloneOpts, verbose); + } catch (error) { + if (verbose) { + console.error(error); + } + throw new Error(`Cloning of ${this.packageConfig.getPackageRepo()} failed!`); + } + + // Do a second check to verify if clone seems to have succeeded + if (!(await this.isValidRepo(packageDir, checkRepoAction))) { + throw new Error(`Problem detected when cloning ${this.packageConfig.getPackageRepo()}!`); + } } } @@ -80,7 +103,7 @@ export class PackageDownloader { checkRepoAction = CheckRepoActions.IS_REPO_ROOT; } - await this._checkForValidRepo(packageDir, cloneOpts, checkRepoAction); + await this._checkForValidRepo(packageDir, cloneOpts, checkRepoAction, verbose); this.git = simpleGit(packageDir); await this._updateRepository(checkRepoAction, verbose); diff --git a/src/modules/package.ts b/src/modules/package.ts index f829a89..8f077f2 100644 --- a/src/modules/package.ts +++ b/src/modules/package.ts @@ -93,29 +93,33 @@ export class PackageConfig { } async getPackageVersions(verbose?: boolean): Promise { - try { - const packageInformation = await packageDownloader(this).downloadPackage({ checkVersionOnly: true, verbose: verbose }); - const packageVersionTags = await packageInformation.tags(); - return packageVersionTags; + const packageInformation = await packageDownloader(this).downloadPackage({ checkVersionOnly: true, verbose: verbose }); + const packageVersionTags = await packageInformation.tags(); + return packageVersionTags; + /* } catch (error) { + console.log(`vvv`); console.log(error); + console.log(`www`); } return { all: [], latest: '', - }; + };*/ } async downloadPackageVersion(verbose?: boolean): Promise { try { await packageDownloader(this).downloadPackage({ verbose: verbose }); } catch (error) { - console.error(error); + if (verbose) { + console.error(error); + } // If repo exist but not version we will end up with default-version // of that repo, and on subsequent runs tooling will say that the missing version // actually exists! To prevent this we remove the directory of the missing version! CliFileSystem.removeSync(this.getPackageDirectoryWithVersion()); - throw new Error(`Cannot find package ${this.getPackageName()}:${this.version}`); + throw new Error(`Downloading package ${this.getPackageName()}:${this.version} failed!`); } return; } diff --git a/src/modules/projectConfig/projectConfigFileReader.ts b/src/modules/projectConfig/projectConfigFileReader.ts index e750bd0..aa05a23 100644 --- a/src/modules/projectConfig/projectConfigFileReader.ts +++ b/src/modules/projectConfig/projectConfigFileReader.ts @@ -46,18 +46,21 @@ export class MultiFormatConfigReader implements IProjectConfigReader { let config: ProjectConfig | null = null; for (const reader of projectConfigReaders) { + let first: boolean = true; try { config = reader.read(cliVersion, path, ignoreLock); if (config !== null) { break; } } catch (error: any) { - console.warn(`Warning: ${path} not in expected format: ${error.message}, falling back to legacy format reading.`); + // This could be format error, but it could also be that repo/tag-settings are faulty, repo cannot be reached and + // similar, for example that "velocitas init" did not succeed! + console.warn(`Error reported by config reader ${reader.constructor.name}: ${error.message}`); } } if (config === null) { - throw new Error(`Unable to read ${path}: unknown format!`); + throw new Error(`Unable to successfully read and interpret ${path}!`); } return config; diff --git a/src/modules/projectConfig/projectConfigLock.ts b/src/modules/projectConfig/projectConfigLock.ts index a70854d..42ec144 100644 --- a/src/modules/projectConfig/projectConfigLock.ts +++ b/src/modules/projectConfig/projectConfigLock.ts @@ -32,7 +32,7 @@ export class ProjectConfigLock implements ProjectConfigLockAttributes { public findVersion(packageName: string): string { const packageVersion = this.packages.get(packageName); if (!packageVersion) { - throw new Error(`Package '${packageName}' not found in lock file.`); + throw new Error(`Package '${packageName}' not found in lock file. Have you performed "velocitas init"?`); } return packageVersion; } diff --git a/test/unit/projectConfigIO.test.ts b/test/unit/projectConfigIO.test.ts index 840990e..e545991 100644 --- a/test/unit/projectConfigIO.test.ts +++ b/test/unit/projectConfigIO.test.ts @@ -221,7 +221,7 @@ describe('projectConfigIO - module', () => { it('should handle errors when parsing .velocitas.json file', () => { const readFileStub = sinon.stub(CliFileSystem, 'readFileSync').throws(); const projectConfigFileReader = () => ProjectConfigIO.read('', configFilePath, true); - expect(projectConfigFileReader).to.throw(`Unable to read ${configFilePath}: unknown format!`); + expect(projectConfigFileReader).to.throw(`UUnable to successfully read and interpret ${configFilePath}`); readFileStub.restore(); });