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

Handle invalid argument errors #6045

Merged
merged 3 commits into from
Jan 30, 2023
Merged

Handle invalid argument errors #6045

merged 3 commits into from
Jan 30, 2023

Conversation

natemoo-re
Copy link
Member

@natemoo-re natemoo-re commented Jan 30, 2023

Changes

  • Previously, the dev server completely crashed when doing something like
---
import Foo from '../components/Foo.astro';
// Called directly via function call
console.log(Foo())
---
// Called inside an expression without `<Foo />` syntax
{items.map(Foo)}
  • This PR fixes this situation by validating the input arguments before attempting to render
  • If the arguments are invalid, we now throw a new InvalidComponentArgs error with helpful info

CleanShot 2023-01-30 at 13 20 57@2x

Testing

Tested manually since this is a smaller one. Can add a test if needed

Docs

/cc @withastro/maintainers-docs for feedback!

@natemoo-re natemoo-re requested a review from a team as a code owner January 30, 2023 19:19
@changeset-bot
Copy link

changeset-bot bot commented Jan 30, 2023

🦋 Changeset detected

Latest commit: 6655535

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 Jan 30, 2023
@natemoo-re natemoo-re self-assigned this Jan 30, 2023
Copy link
Member

@yanthomasdev yanthomasdev left a comment

Choose a reason for hiding this comment

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

Nice work @natemoo-re, I added a small docs related suggestion, but overall LGTM!

packages/astro/src/core/errors/errors-data.ts Outdated Show resolved Hide resolved
Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com>
@natemoo-re natemoo-re merged commit 41e9715 into main Jan 30, 2023
@natemoo-re natemoo-re deleted the fix/invalid-args-error branch January 30, 2023 20:11
@astrobot-houston astrobot-houston mentioned this pull request Jan 30, 2023
matthewp pushed a commit that referenced this pull request Feb 3, 2023
* fix: add error handling for invalid arguments

* chore: add changeset

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

Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com>

---------

Co-authored-by: Nate Moore <nate@astro.build>
Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com>
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)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants