cli icon indicating copy to clipboard operation
cli copied to clipboard

Bring netlify-branded functions error page to edge functions

Open Skn0tt opened this issue 3 years ago • 6 comments

Which problem is this feature request solving?

At the moment, when an edge function throws an uncaught exception, we just show the body of the 500 returned. The fact that an uncaught exception led to this is non-obvious.

Describe the solution you'd like

Instead, we should use the Netlify-branded error page that was introduced in https://github.com/netlify/cli/pull/4486 also for edge functions. We've implemented a similar thing for production via https://github.com/netlify/stargate/pull/554, which uses the structured errors returned from edge functions via https://github.com/netlify/edge-functions-bootstrap/pull/38.

Pull request (optional)

  • [X] I can submit a pull request.

Skn0tt avatar May 31 '22 12:05 Skn0tt

From Slack:

I am assuming, just to clarify, that we mean setting this up for local development using netlify/cli?

The easiest way to reproduce this is to have a repo that has an edge function with an error, deploy the site, and invoke the function.

On a live site, we should see an error page.

If locally, we run netlify dev and invoke the function, we don't see the Netlify branded error page.

minivan avatar Aug 15 '22 11:08 minivan

I think I was a bit confused because @Skn0tt mentioned

We've implemented a similar thing for production via https://github.com/netlify/stargate/pull/554, which uses the structured errors returned from edge functions via https://github.com/netlify/edge-functions-bootstrap/pull/38.

But I guess the difference then is that this issue is not about those structured errors, but about uncaught exceptions?

khendrikse avatar Aug 15 '22 11:08 khendrikse

In the first implementation of these error pages, we had full stack traces included in the error page, including for uncaught exceptions inside of user code. These were visible to all visitors, and disclosed both that the site is hosted by Netlify, and potentially leaked some source code internals (stacktraces contain file names, function names etc). So we've changed it so that the page itself shows only a bland error code like "Uncaught exception", and then there's a link at the bottom that leads to the edge functions log page. See https://edge-functions-examples.netlify.app/error for an example.

For the CLI though, I think we'd like to change that up a bit. Since there's no logs page to point towards, and we don't need to hide implementation details in local dev, I think it'd be fine to show the full stacktrace.

Skn0tt avatar Aug 15 '22 13:08 Skn0tt

Here's some pointers towards what code we'd need to change:

In https://github.com/netlify/edge-functions-bootstrap/blob/2ca738749a57957640c9c8132f512810ebc79d88/src/bootstrap/handler.ts#L38-L43, we'd need to add a "local dev" mode that returns not only String(error), but also error.stack and other metadata.

Then in the local-dev codebase, we'd need to check for the x-nf-uncaught-error error, and render the existing error page template.

Skn0tt avatar Aug 15 '22 13:08 Skn0tt

So if I understand correctly, this is already solved then for production?

But it needs to also be implemented on local dev so we can see details of what is going wrong when developing?

khendrikse avatar Aug 15 '22 13:08 khendrikse

@khendrikse this marked as "In progress". Can you share an update?

eduardoboucas avatar Sep 13 '22 14:09 eduardoboucas