diff options
author | 2023-03-27 17:37:28 -0400 | |
---|---|---|
committer | 2023-03-27 17:37:28 -0400 | |
commit | 88a8e7ae1a460b2193e35ca60be8c4217864ab10 (patch) | |
tree | d1f1ac661898d5d718e8e34d8dc7e1936532c044 | |
parent | 4b899d2257f9f9d3b695dd6f3982cfa88d581ef6 (diff) | |
download | astro-88a8e7ae1a460b2193e35ca60be8c4217864ab10.tar.gz astro-88a8e7ae1a460b2193e35ca60be8c4217864ab10.tar.zst astro-88a8e7ae1a460b2193e35ca60be8c4217864ab10.zip |
fix: check for nonexistent templates
-rw-r--r-- | packages/create-astro/src/actions/template.ts | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/packages/create-astro/src/actions/template.ts b/packages/create-astro/src/actions/template.ts index 4f7e751e9..1684a4c08 100644 --- a/packages/create-astro/src/actions/template.ts +++ b/packages/create-astro/src/actions/template.ts @@ -81,11 +81,18 @@ export default async function copyTemplate(tmpl: string, ctx: Context) { } catch (err: any) { fs.rmdirSync(ctx.cwd); if (err.message.includes('404')) { - await error('Error', `Template ${color.reset(tmpl)} ${color.dim('does not exist!')}`); + throw new Error(`Template ${color.reset(tmpl)} ${color.dim('does not exist!')}`); } else { - console.error(err.message); + throw new Error(err.message); } - ctx.exit(1); + } + + // It's possible the repo exists (ex. `withastro/astro`), + // But the template route is invalid (ex. `withastro/astro/examples/DNE`). + // `giget` doesn't throw for this case, + // so check if the directory is still empty as a heuristic. + if (fs.readdirSync(ctx.cwd).length === 0) { + throw new Error(`Template ${color.reset(tmpl)} ${color.dim('is empty!')}`); } // Post-process in parallel |