Skip to content

Commit 194bbba

Browse files
authored
Improve error handling for .velocitas.json (#309)
* Improve error handling for .velocitas.json
1 parent 3edb47a commit 194bbba

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/modules/package.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ export class PackageConfig {
111111
await packageDownloader(this).downloadPackage({ verbose: verbose });
112112
} catch (error) {
113113
console.error(error);
114+
// If repo exist but not version we will end up with default-version
115+
// of that repo, and on subsequent runs tooling will say that the missing version
116+
// actually exists! To prevent this we remove the directory of the missing version!
117+
CliFileSystem.removeSync(this.getPackageDirectoryWithVersion());
118+
throw new Error(`Cannot find package ${this.getPackageName()}:${this.version}`);
114119
}
115120
return;
116121
}
@@ -128,14 +133,21 @@ export class PackageConfig {
128133
}
129134

130135
readPackageManifest(): PackageManifest {
136+
let data;
131137
try {
132138
const path = this.getManifestFilePath();
133-
const config: PackageManifest = deserializePackageJSON(CliFileSystem.readFileSync(path));
134-
return config;
139+
data = CliFileSystem.readFileSync(path);
135140
} catch (error) {
136141
console.log(`Cannot find package ${this.getPackageName()}:${this.version}. Please upgrade or init first!`);
137142
throw new Error(`Cannot find package ${this.getPackageName()}:${this.version}`);
138143
}
144+
try {
145+
const config: PackageManifest = deserializePackageJSON(data);
146+
return config;
147+
} catch (error: any) {
148+
const errorMessage = error?.message || 'Unknown error occurred';
149+
throw new Error(`Cannot parse manifest file for ${this.getPackageName()}:${this.version}.\n${errorMessage}`);
150+
}
139151
}
140152
}
141153

0 commit comments

Comments
 (0)