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

Improve error handling #3859

Merged
merged 42 commits into from
Jul 19, 2022
Merged

Improve error handling #3859

merged 42 commits into from
Jul 19, 2022

Conversation

natemoo-re
Copy link
Member

@natemoo-re natemoo-re commented Jul 8, 2022

Changes

  • We had a custom page for 500 errors (which was really any error that happens on the server)
  • This PR replaces that with Vite's built-in error overlay
  • Improves display for generic errors by deriving a code frame automatically
  • Updates JSX renderers to "tag" local exports with the renderer matched by our import scanner, which means we can throw much better errors when there's a problem with a JSX file.
    Before
    Errors were uncaught, component ran through many renderers, streaming response would hang indefinitely

before

After
Errors are caught, component only runs through the correct renderer (which errors helpfully), streaming response closes and Vite's error overlay is shown

after

Testing

Updated tests for error conditions. Unfortunately was unable to automate error overlay tests due to CI limitations.

Docs

QoL improvement

@changeset-bot
Copy link

changeset-bot bot commented Jul 8, 2022

⚠️ No Changeset found

Latest commit: 1a2a883

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jul 8, 2022
@natemoo-re natemoo-re changed the title Feat/improve errors Improve error handling Jul 8, 2022
@natemoo-re natemoo-re self-assigned this Jul 8, 2022
@natemoo-re natemoo-re force-pushed the feat/improve-errors branch from 69d262a to bd7ee31 Compare July 12, 2022 17:07
@natemoo-re
Copy link
Member Author

E2E tests are failing because of the issue fixed by #3915!

Copy link
Contributor

@bholmesdev bholmesdev left a comment

Choose a reason for hiding this comment

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

Some comments, but verrory impressive!

packages/astro/src/core/render/dev/index.ts Outdated Show resolved Hide resolved
packages/astro/src/runtime/server/index.ts Outdated Show resolved Hide resolved
packages/astro/src/runtime/server/index.ts Show resolved Hide resolved
packages/astro/src/runtime/server/index.ts Show resolved Hide resolved
Copy link
Contributor

@bholmesdev bholmesdev left a comment

Choose a reason for hiding this comment

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

LGTM once smoke passes ✅

Copy link
Member

@FredKSchott FredKSchott left a comment

Choose a reason for hiding this comment

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

Left some comments but not blocking / LGTM otherwise

packages/astro/src/core/create-vite.ts Outdated Show resolved Hide resolved
packages/astro/src/core/errors.ts Outdated Show resolved Hide resolved
packages/astro/src/template/5xx.ts Show resolved Hide resolved
Copy link
Contributor

@matthewp matthewp left a comment

Choose a reason for hiding this comment

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

I'm not understanding how __astro_tag_component__ is relevant to error messages. Is it? If its for the sake of speeding up rendering I think that should be done in a separate issue.


We used to cache the result of .check() in a weakmap. This worked with any framework and didn't rely on AST parsing. I can't remember why we removed that, but if this is being done for performance I'd rather rethink about that approach.

@natemoo-re natemoo-re merged commit 4412fe6 into main Jul 19, 2022
@natemoo-re natemoo-re deleted the feat/improve-errors branch July 19, 2022 21:47
@astrobot-houston astrobot-houston mentioned this pull request Jul 20, 2022
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.

4 participants