aboutsummaryrefslogtreecommitdiff
path: root/packages/create-astro/src
diff options
context:
space:
mode:
authorGravatar Matt Kane <m@mk.gg> 2024-07-29 13:49:01 +0100
committerGravatar GitHub <noreply@github.com> 2024-07-29 13:49:01 +0100
commitd27cf6df7bd612642a1e8da5948333b00b70e8bd (patch)
tree01a2fd7c6ff8b2079cff23f07fab84776f33ec8d /packages/create-astro/src
parent504c383e20dfb5d8eb0825a70935f221b43577b2 (diff)
downloadastro-d27cf6df7bd612642a1e8da5948333b00b70e8bd.tar.gz
astro-d27cf6df7bd612642a1e8da5948333b00b70e8bd.tar.zst
astro-d27cf6df7bd612642a1e8da5948333b00b70e8bd.zip
fix(create-astro): log fetch errors (#11567)
Diffstat (limited to 'packages/create-astro/src')
-rw-r--r--packages/create-astro/src/actions/template.ts22
1 files changed, 18 insertions, 4 deletions
diff --git a/packages/create-astro/src/actions/template.ts b/packages/create-astro/src/actions/template.ts
index 3afd5f3cf..5169c63e3 100644
--- a/packages/create-astro/src/actions/template.ts
+++ b/packages/create-astro/src/actions/template.ts
@@ -83,7 +83,6 @@ export function getTemplateTarget(tmpl: string, ref = 'latest') {
export default async function copyTemplate(tmpl: string, ctx: Context) {
const templateTarget = getTemplateTarget(tmpl, ctx.ref);
-
// Copy
if (!ctx.dryRun) {
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!')}`);
- } 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`),