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

Missing/weak validation on glob loader #12795

Closed
1 task
CGamesPlay opened this issue Dec 20, 2024 · 1 comment · Fixed by #12798
Closed
1 task

Missing/weak validation on glob loader #12795

CGamesPlay opened this issue Dec 20, 2024 · 1 comment · Fixed by #12798
Assignees
Labels
- P2: nice to have Not breaking anything but nice to have (priority) feat: content collections Related to the Content Collections feature (scope)

Comments

@CGamesPlay
Copy link

CGamesPlay commented Dec 20, 2024

Astro Info

Astro                    v5.1.0
Node                     v22.11.0
System                   macOS (arm64)
Package Manager          unknown
Output                   static
Adapter                  none
Integrations             @astrojs/starlight
                         @astrojs/mdx
                         @astrojs/tailwind

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

No response

Describe the Bug

I just upgraded to Astro 5 and found the error handling on glob to be very weak. Problems:

  1. The "base" directory is relative to my project root, not relative to the file declaring the content collections. The examples in the docs highlight this, but the behavior is unintuitive, which makes proper error handling more important.
  2. Providing an invalid "base" directory does not give any error, it just produces an empty collection. This makes it difficult for me to identify if the problem is the base directory (which has an unclear pwd) or my pattern. For example, use glob({ base: "/this/path/does/not/exist", pattern: "*" })
  3. The console warning that you get when you reference such an invalid collection isn't very helpful: "The collection "foo" does not exist or is empty. Ensure a collection directory with this name exists." This is incorrect advice in Astro 5, and you know the collection does exist, it is just empty.
  4. Bonus wishlist: if the glob directory exists and is not empty, but all paths are filtered out by the pattern, instead of the above error message, it would be nice if glob gave a message saying that "some files exist, but they are all excluded by the pattern". This is important because I was using an invalid pattern (**/[^_]*.mdx?), but there's no validation on this field.

What's the expected result?

Documented inline, above.

Thank you to the team behind Astro for all of the hard work. I know that 5.0 is very new, and I hope that increasing the error handling here will help other upgrading users to have a smoother experience.

Link to Minimal Reproducible Example

https://docs.astro.build/en/guides/upgrade-to/v5/#updating-existing-collections

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 Dec 20, 2024
@ascorbic ascorbic self-assigned this Dec 20, 2024
@ascorbic ascorbic added - P2: nice to have Not breaking anything but nice to have (priority) feat: content collections Related to the Content Collections feature (scope) and removed needs triage Issue needs to be triaged labels Dec 20, 2024
@CGamesPlay
Copy link
Author

Great turnaround time. Thanks for fixing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: nice to have Not breaking anything but nice to have (priority) feat: content collections Related to the Content Collections feature (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants