Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message for third-party template 404s #5920

Merged
merged 2 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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