Skip to content

Conversation

@jp-knj
Copy link
Member

@jp-knj jp-knj commented May 6, 2025

Changes

  • refactor(astro): Replaced generic Error throws with AstroError #13759 (comment)
  • Introduced two scoped error definitions in packages/astro/src/core/errors/errors-data.ts
    • FileGlobNotSupported – thrown when a glob pattern is passed to file() loader.
    • FileParserNotFound – thrown when no parser can be determined for the file extension.
      Both follow the project’s error‐data convention (name | title | message | hint | docs tags).
  • Replaced generic Error throws with AstroError in
    packages/astro/src/content/loader/file.ts.
    • throw new AstroError(FileGlobNotSupported)
    • throw new AstroError({ …FileParserNotFound, message: FileParserNotFound.message(fileName) })
  • Added a changeset (pnpm exec changeset) so these improvements surface in release notes.

Testing

  • Ran the full test suite: pnpm test – no regressions.
  • Manual Smoke Tests
    1. file('data/*.json') → displays File glob pattern not supported banner.
    2. file('data/example.xml') → displays File parser not found banner with doc link.

No new automated tests — behaviour is unchanged; only error wiring differs.

Docs

No public-API changes. Docs remain valid.

@changeset-bot
Copy link

changeset-bot bot commented May 6, 2025

🦋 Changeset detected

Latest commit: 5325406

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) docs pr labels May 6, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented May 6, 2025

CodSpeed Performance Report

Merging #13761 will not alter performance

Comparing jp-knj:replace-astro-error-2 (5325406) with main (9d49297)

Summary

✅ 6 untouched benchmarks

@jp-knj jp-knj marked this pull request as ready for review May 7, 2025 11:10
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @jp-knj. The position of the errors is important in this file. You must place these errors after this line, and before the @kind heading comment :

@jp-knj jp-knj force-pushed the replace-astro-error-2 branch from 884ea2e to 7f48b38 Compare May 7, 2025 13:16
@ematipico ematipico requested a review from sarah11918 May 7, 2025 13:42
@jp-knj
Copy link
Member Author

jp-knj commented May 7, 2025

@ematipico
Thank you, modify the position of error definitions

@sarah11918
Copy link
Member

sarah11918 commented May 7, 2025

Are these content collections errors? If so, they need to go in the Content Collections section which is around line 1566!

All the errors will show up in the order they are written, including under the appropriate heading section:

image

Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some quick initial comments here before editing for docs!

@jp-knj
Copy link
Member Author

jp-knj commented May 7, 2025

Are these content collections errors? If so, they need to go in the Content Collections section which is around line 1566!

All the errors will show up in the order they are written, including under the appropriate heading section:

image

is two errors Okay after L1557, before L1559?

@jp-knj jp-knj force-pushed the replace-astro-error-2 branch from 8703693 to 684c028 Compare May 7, 2025 15:23
Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating based on my original comments!

Note: these errors are still not quite in the correct location! 😄 In this spot, they are showing up just BEFORE the proper heading. They should go AFTER the Content Collections heading, and typically we put newer errors at the bottom. You can check the live version of docs if it's difficult to picture here: https://docs.astro.build/en/reference/error-reference/ Figure out which message you want to follow, and place your messages after that one (for example, the last content collections error currently is "Unsupported transform in content config" so you could place it directly after that one, before the next heading.

Otherwise, I've made some suggestions below based on the structure of our error messages, and also where I think it would be helpful to send people for help. (e.g. if they passed a glob pattern, they probably don't need to go see how to construct a glob pattern, but instead, they need to see how the loaders work and which one should be used with a glob pattern)

See if what I've suggested makes sense, and please correct as necessary!

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! We can merge it once @sarah11918 approves it :)

@jp-knj
Copy link
Member Author

jp-knj commented May 9, 2025

Thanks too!!

I learned all about:

  • Both the file loader and the glob loader are part of Astro’s Content Collections API.
    So, any errors about them naturally occur while working with Content Collections.
  • In the error reference, sections are organized to match how users think when troubleshooting.
    For example:
    “I got an error while setting up Content Collections → I should check the Content Collections section.”
    That’s why grouping these under Content Collection Errors makes sense.

Then, to summarize

  • Feature grouping → because they are part of Content Collections.
  • Documentation structure → to keep the generated docs consistent.
  • Maintenance rule → to place new entries at the end of the section.

That’s why placing them under Content Collections is the best choice.

I fully got them!

Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for these helpful error messages, @jp-knj ! We are happy to have your contribution! 🎉

@ematipico ematipico merged commit a2e8463 into withastro:main May 13, 2025
15 of 16 checks passed
@astrobot-houston astrobot-houston mentioned this pull request May 13, 2025
openscript pushed a commit to openscript/astro that referenced this pull request Sep 12, 2025
…3761)

* put them to follow a pattern for errors

* feat: update changeset

* chore: modify message

Co-authored-by: Sarah Rainsberger <[email protected]>

* chore: update the position of two error definitions and modify text

* delete parser hint and add global pattern hint

* Update packages/astro/src/core/errors/errors-data.ts

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update packages/astro/src/core/errors/errors-data.ts

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update packages/astro/src/core/errors/errors-data.ts

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update packages/astro/src/core/errors/errors-data.ts

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update packages/astro/src/core/errors/errors-data.ts

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update packages/astro/src/core/errors/errors-data.ts

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update packages/astro/src/core/errors/errors-data.ts

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update packages/astro/src/core/errors/errors-data.ts

Co-authored-by: Sarah Rainsberger <[email protected]>

* fix: modify text

* fix: update the position why: this errors about them naturally occur while working with Content Collections

* fix: modify text

---------

Co-authored-by: jp-knj <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs pr pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants