From 99c5c2a2e3d87b77d81b1c576575dd5db70c5f22 Mon Sep 17 00:00:00 2001 From: Chris Swithinbank Date: Sat, 21 Jan 2023 00:04:39 +0100 Subject: [PATCH] Improve error message for third-party template 404s (#5920) --- .changeset/large-hotels-give.md | 5 +++++ packages/create-astro/src/index.ts | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 .changeset/large-hotels-give.md diff --git a/.changeset/large-hotels-give.md b/.changeset/large-hotels-give.md new file mode 100644 index 000000000000..4667b73daaae --- /dev/null +++ b/.changeset/large-hotels-give.md @@ -0,0 +1,5 @@ +--- +'create-astro': patch +--- + +Improve error message for third-party template 404s diff --git a/packages/create-astro/src/index.ts b/packages/create-astro/src/index.ts index 4a4008438868..5b4973a12123 100644 --- a/packages/create-astro/src/index.ts +++ b/packages/create-astro/src/index.ts @@ -192,7 +192,20 @@ export async function main() { } catch (err: any) { fs.rmdirSync(cwd); if (err.message.includes('404')) { - console.error(`Template ${color.underline(options.template)} does not exist!`); + console.error(`Could not find template ${color.underline(options.template)}!`); + if (isThirdParty) { + const hasBranch = options.template.includes('#'); + if (hasBranch) { + console.error('Are you sure this GitHub repo and branch exist?'); + } else { + console.error( + `Are you sure this GitHub repo exists?` + + `This command uses the ${color.bold('main')} branch by default.\n` + + `If the repo doesn't have a main branch, specify a custom branch name:\n` + + color.underline(options.template + color.bold('#branch-name')) + ); + } + } } else { console.error(err.message); }