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

Allow for empty content collections #8336

Closed
1 task
pReya opened this issue Aug 31, 2023 · 4 comments · Fixed by #8382
Closed
1 task

Allow for empty content collections #8336

pReya opened this issue Aug 31, 2023 · 4 comments · Fixed by #8382
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: content collections Related to the Content Collections feature (scope)

Comments

@pReya
Copy link
Contributor

pReya commented Aug 31, 2023

Astro Info

Astro version            v2.9.6
Package manager          npm
Platform                 darwin
Architecture             arm64
Adapter                  Couldn't determine.
Integrations             @astrojs/react, @astrojs/tailwind, auto-import, @astrojs/mdx

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

I'm well aware some might see this as a new feature, but I have to disagree. Content collections should be able to handle a "empty state" – meaning you should be able to use a content collection which has no items. Currently, this will always throw an error, so the page basically breaks. But there are plenty valid use cases for empty collections and it should be possible to still use the site (e.g. throw a warning instead of an error).

Also the error is technically not correct. This is what it says:

 error   The collection examples does not exist. Ensure a collection directory with this name exists.

Yet, this is also the error, when the folder exists, but there's just no file in it.

Am I missing something or is this really an oversight in the concept of content collections?

What's the expected result?

Page should still render

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-agpp3a?file=src%2Fpages%2Findex.astro

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Aug 31, 2023
@natemoo-re
Copy link
Member

I'd consider this mostly to be a bad error message, but we also should probably just warn instead of throw. Seems fair to me.

@natemoo-re natemoo-re added feat: content collections Related to the Content Collections feature (scope) - P3: minor bug An edge case that only affects very specific usage (priority) labels Aug 31, 2023
@github-actions github-actions bot removed the needs triage Issue needs to be triaged label Aug 31, 2023
@DerTimonius
Copy link
Contributor

I would like to take a look into this!

@DerTimonius
Copy link
Contributor

@natemoo-re I have a quick question regarding the warning instead of throwing an error: in #8382 I removed the AstroError and changed it to a zodIssue, but I'm not sure if this would be the correct way. Was wondering, if there is a way to use something like logger.warn?

@pReya
Copy link
Contributor Author

pReya commented Sep 14, 2023

@natemoo-re Push! Can you help @DerTimonius ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: content collections Related to the Content Collections feature (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants