0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-30 22:03:56 -05:00

fix(create-astro): log fetch errors (#11567)

This commit is contained in:
Matt Kane 2024-07-29 13:49:01 +01:00 committed by GitHub
parent 504c383e20
commit d27cf6df7b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
'create-astro': patch
---
Logs underlying error when a template cannot be downloaded

View file

@ -83,7 +83,6 @@ export function getTemplateTarget(tmpl: string, ref = 'latest') {
export default async function copyTemplate(tmpl: string, ctx: Context) { export default async function copyTemplate(tmpl: string, ctx: Context) {
const templateTarget = getTemplateTarget(tmpl, ctx.ref); const templateTarget = getTemplateTarget(tmpl, ctx.ref);
// Copy // Copy
if (!ctx.dryRun) { if (!ctx.dryRun) {
try { try {
@ -104,11 +103,26 @@ export default async function copyTemplate(tmpl: string, ctx: Context) {
} }
} }
if (err.message.includes('404')) { if (err.message?.includes('404')) {
throw new Error(`Template ${color.reset(tmpl)} ${color.dim('does not exist!')}`); throw new Error(`Template ${color.reset(tmpl)} ${color.dim('does not exist!')}`);
} else {
throw new Error(err.message);
} }
if (err.message) {
error('error', err.message);
}
try {
// The underlying error is often buried deep in the `cause` property
// This is in a try/catch block in case of weirdnesses in accessing the `cause` property
if ('cause' in err) {
// This is probably included in err.message, but we can log it just in case it has extra info
error('error', err.cause);
if ('cause' in err.cause) {
// Hopefully the actual fetch error message
error('error', err.cause?.cause);
}
}
} catch {}
throw new Error(`Unable to download template ${color.reset(tmpl)}`);
} }
// It's possible the repo exists (ex. `withastro/astro`), // It's possible the repo exists (ex. `withastro/astro`),