Skip to content

Commit

Permalink
Improve error message for third-party template 404s (#5920)
Browse files Browse the repository at this point in the history
  • Loading branch information
delucis authored and matthewp committed Jan 26, 2023
1 parent f27570d commit 99c5c2a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/large-hotels-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-astro': patch
---

Improve error message for third-party template 404s
15 changes: 14 additions & 1 deletion packages/create-astro/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 99c5c2a

Please sign in to comment.