Skip to content

feat(astro): Add tracking of errors during HTML streaming #15995

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

Merged
merged 2 commits into from
Apr 7, 2025

Conversation

Fryuni
Copy link
Contributor

@Fryuni Fryuni commented Apr 7, 2025

Astro components are rendered in a stream, so if a component that is not the page fails during a request, this error is not thrown by the await next() call, only when the component is reached in the response stream.

The code was iterating over the response stream assuming it was infallible, so component errors were being ignored by sentry and hidden from the user. This PR wraps the iteration on a try/catch pair to report the error and forward it along to the error handling pipeline.


Before submitting a pull request, please take a look at our
Contributing guidelines and verify:

  • If you've added code that should be tested, please add tests.
  • Ensure your code lints and the test suite passes (yarn lint) & (yarn test).

}
} catch (e) {
sendErrorToSentry(e);
controller.error(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 think we should still rethrow this error, otherwise we risk breaking people who rely on this.

Is controller.error(e); robust enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

controller.error is what rethrows the error on a stream. Throwing from this function is ignored (it was being ignored before, so no one was relying on the error working).

The test is checking that the error is being forwarded.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm I'm not sure if we want to capture this error at all. The only reason we're even going through the body is to inject our <meta> tags and if it's us causing the error by doing so, we shouldn't report it.

Or would we even swallow errors if we didn't modify the HTML?

The try/catch is probably a good idea anyway to degrade gracefully 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I'm not sure if we want to capture this error at all.

This is a user thrown error that is being missed and shows as Internal Server Error on rendering. I think it makes sense for Sentry to capture and report it, but most of all it makes sense to not drop it and pass it forward so errors from the user are not discarded.

We could have some more verbose code to handle only errors from the iterator and not from any part of the <meta> tag inside the loop.

Copy link
Member

Choose a reason for hiding this comment

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

Discussed this with @AbhiPrasad offline and for now we think it's fine to leave as-is. The injection is fairly low risk (famous last words lol). In case we get reports about our HTML injection logic causing errors, we can still revisit.

Thanks for contributing!

Copy link
Member

@AbhiPrasad AbhiPrasad 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 @Fryuni! We'll try and get this out with the next release

@AbhiPrasad AbhiPrasad merged commit 3c1a9d9 into getsentry:develop Apr 7, 2025
34 checks passed
AbhiPrasad added a commit that referenced this pull request Apr 7, 2025
This PR adds the external contributor to the CHANGELOG.md file, so that
they are credited for their contribution. See #15995

Co-authored-by: AbhiPrasad <18689448+AbhiPrasad@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants