Skip to content

Commit

Permalink
fix(create-astro): log fetch errors (#11567)
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic authored Jul 29, 2024
1 parent 504c383 commit d27cf6d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/gorgeous-timers-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-astro': patch
---

Logs underlying error when a template cannot be downloaded
22 changes: 18 additions & 4 deletions packages/create-astro/src/actions/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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`),
Expand Down

0 comments on commit d27cf6d

Please sign in to comment.