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

Add pretty-error page infrastructure #436

Merged
merged 1 commit into from
Nov 18, 2022
Merged

Add pretty-error page infrastructure #436

merged 1 commit into from
Nov 18, 2022

Conversation

mrbbot
Copy link
Contributor

@mrbbot mrbbot commented Nov 18, 2022

This adds Miniflare 2's pretty-error page powered by Youch to Miniflare 3.

Unfortunately, due to a bug in workerd, errors thrown asynchronously by native APIs don't have stacks. This means we can't extract the stack trace from dispatching to the user worker by try/catch.

As a stop-gap solution, if the MF-Experimental-Error-Stack header exists and is truthy on the response from the user worker, the body will be interpreted as a JSON-error of the form
{ message?: string, name?: string, stack?: string }. stack will be source-mapped if possible.

Another issue is that workerd gives all service-worker scripts the name "worker.js", so if multiple service-workers are defined, we can't identify which one threw. In this case, we don't display sources in the pretty-error page.

Hopefully, we can fix both of these issues in workerd. We should be able to reuse most of this infrastructure with try/catchs too.

@mrbbot mrbbot added the tre Relating to Miniflare 3 label Nov 18, 2022
@mrbbot mrbbot added this to the 3.0.0 milestone Nov 18, 2022
@changeset-bot
Copy link

changeset-bot bot commented Nov 18, 2022

⚠️ No Changeset found

Latest commit: 2083935

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.

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

This adds Miniflare 2's pretty-error page powered by
[Youch](https://github.com/poppinss/youch) to Miniflare 3.

Unfortunately, due to a bug in `workerd`, errors thrown
asynchronously by native APIs don't have `stack`s. This means we
can't extract the `stack` trace from dispatching to the user worker
by `try`/`catch`.

As a stop-gap solution, if the `MF-Experimental-Error-Stack` header
exists and is truthy on the response from the user worker, the body
will be interpreted as a JSON-error of the form
`{ message?: string, name?: string, stack?: string }`. `stack` will
be source-mapped if possible.

Another issue is that `workerd` gives all service-worker scripts the
name "worker.js", so if multiple service-workers are defined, we
can't identify which one threw. In this case, we don't display
sources in the pretty-error page.

Hopefully, we can fix both of these issues in `workerd`. We should be
able to reuse most of this infrastructure with `try`/`catch`s too.
@mrbbot mrbbot merged commit f42ea31 into tre Nov 18, 2022
@mrbbot mrbbot deleted the tre-pretty-error branch November 18, 2022 12:23
mrbbot added a commit to cloudflare/workers-sdk that referenced this pull request Nov 21, 2022
This PR enables Miniflare 3's pretty-error page with middleware. See
cloudflare/miniflare#436 for an explanation of why we need to do this
in the first place.
mrbbot added a commit to cloudflare/workers-sdk that referenced this pull request Nov 21, 2022
This PR enables Miniflare 3's pretty-error page with middleware. See
cloudflare/miniflare#436 for an explanation of why we need to do this
in the first place.
mrbbot added a commit to cloudflare/workers-sdk that referenced this pull request Nov 21, 2022
This PR enables Miniflare 3's pretty-error page with middleware. See
cloudflare/miniflare#436 for an explanation of why we need to do this
in the first place.
mrbbot added a commit to cloudflare/workers-sdk that referenced this pull request Nov 21, 2022
This PR enables Miniflare 3's pretty-error page with middleware. See
cloudflare/miniflare#436 for an explanation of why we need to do this
in the first place.
mrbbot added a commit to cloudflare/workers-sdk that referenced this pull request Nov 21, 2022
* Fix file-watching when using middleware with service workers

Previously, when middleware was enabled, service worker user code was
being bundled as part of the middleware facade application, not in
the final bundling step with `watch` enabled. This meant changes to
user code were not picked up. This change restructures the service
worker middleware loader and bundling code as an IIFE, that gets
injected into the final bundle. This also has the positive side
effect that middleware internals aren't exposed to users.

* Enable pretty-error page when using `--experimental-local`

This PR enables Miniflare 3's pretty-error page with middleware. See
cloudflare/miniflare#436 for an explanation of why we need to do this
in the first place.
mrbbot added a commit to cloudflare/workers-sdk that referenced this pull request Nov 15, 2023
This change ensures Miniflare's pretty error page includes the URL and
headers of the incoming request, rather than Miniflare's internal
request from `workerd` to the loopback server.

The request URL has been incorrect since the pretty error page was
introduced into version 3 (cloudflare/miniflare#436). The request
headers have been incorrect since (cloudflare/miniflare#681). This
change also adds some tests to prevent this regressing again.
mrbbot added a commit to cloudflare/workers-sdk that referenced this pull request Dec 8, 2023
This change ensures Miniflare's pretty error page includes the URL and
headers of the incoming request, rather than Miniflare's internal
request from `workerd` to the loopback server.

The request URL has been incorrect since the pretty error page was
introduced into version 3 (cloudflare/miniflare#436). The request
headers have been incorrect since (cloudflare/miniflare#681). This
change also adds some tests to prevent this regressing again.
@thetutlage
Copy link

Hello guys!

I am the creator of Youch and did a rewrite of the package with newer/better design and more extensible API.

I have tagged the beta release of Youch and the README covers it usage in-depth. https://github.com/poppinss/youch

Would love to collaborate with you guys and see if you need anything to make Youch a better fit for the Workers SDK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tre Relating to Miniflare 3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants