fix: improve invalid package version error handling (#159)

* chore: add test case for invalid package versions

* fix: add improved errors for invalid package versions
This commit is contained in:
Cedric van Putten authored and GitHub committed 2022-02-14 07:01:16 -08:00
1 parent 839215f036
commit 94c7d8acbd
3 files changed
+13

No files matched your search

+4
View File
@@ -67019,6 +67019,10 @@ async function resolvePackage(name, range) {
catch (error) {
throw new Error(`Could not resolve ${name}@${range}, reason:\n${error.message || error}`);
}
// thanks npm, for returning a "" json string value for invalid versions
if (!stdout) {
throw new Error(`Could not resolve ${name}@${range}, reason:\nInvalid version`);
}
// thanks npm, for returning a "x.x.x" json value...
if (stdout.startsWith('"')) {
stdout = `[${stdout}]`;
+5
View File
@@ -17,6 +17,11 @@ export async function resolvePackage(name: string, range: string): Promise<strin
throw new Error(`Could not resolve ${name}@${range}, reason:\n${error.message || error}`);
}
// thanks npm, for returning a "" json string value for invalid versions
if (!stdout) {
throw new Error(`Could not resolve ${name}@${range}, reason:\nInvalid version`);
}
// thanks npm, for returning a "x.x.x" json value...
if (stdout.startsWith('"')) {
stdout = `[${stdout}]`;
+4
View File
@@ -22,4 +22,8 @@ describe(resolvePackage, () => {
'Could not resolve'
);
});
it('rejects expo-cli@9999999 with proper error', async () => {
await expect(resolvePackage('expo-cli', '9999999')).rejects.toThrow('Could not resolve');
});
});