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

chore: improve type fidelity for internal error class #9478

Merged
merged 4 commits into from
Dec 20, 2023

Conversation

lilnasy
Copy link
Contributor

@lilnasy lilnasy commented Dec 19, 2023

Changes

  • Add types for the parameters that AstroError passes onto built-in Error
  • Fix misuse of AstroError that the types exposed

Testing

None as this is a maintainer QOL change mostly.

Docs

Does not affect usage.

Copy link

changeset-bot bot commented Dec 19, 2023

🦋 Changeset detected

Latest commit: 7470d29

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 the pkg: astro Related to the core `astro` package (scope) label Dec 19, 2023
@@ -492,7 +492,7 @@ export async function getEntrySlug({
contents = await fs.promises.readFile(fileUrl, 'utf-8');
} catch (e) {
// File contents should exist. Raise unexpected error as "unknown" if not.
throw new AstroError(AstroErrorData.UnknownContentCollectionError, { cause: e });
Copy link
Member

Choose a reason for hiding this comment

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

I still don't understand why the second argument is undefined 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is the message.

const error = new Error("error message", { cause })

AstroError's constructor overrides the message (this.message = errorData.message) anyway so it might be possible to remove the option altogether.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was a bit worried but it was relatively simple.

@github-actions github-actions bot added the pr: docs A PR that includes documentation for review label Dec 19, 2023
@@ -226,7 +226,6 @@ export async function generateImagesForPath(
...AstroErrorData.CouldNotTransformImage,
message: AstroErrorData.CouldNotTransformImage.message(originalFilePath),
},
undefined,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

how did tsc miss this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh its from 9352

@lilnasy lilnasy merged commit dfef925 into withastro:main Dec 20, 2023
13 checks passed
@lilnasy lilnasy deleted the report-error-cause branch December 20, 2023 21:13
@astrobot-houston astrobot-houston mentioned this pull request Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) pr: docs A PR that includes documentation for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants