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

Better error handling #109

Open
3 tasks
cprussin opened this issue Sep 2, 2018 · 6 comments
Open
3 tasks

Better error handling #109

cprussin opened this issue Sep 2, 2018 · 6 comments

Comments

@cprussin
Copy link
Collaborator

cprussin commented Sep 2, 2018

We need better sad-path handling. Things like:

  • Request closed by client while in flight
  • Exception while running router
  • Others?
@cprussin
Copy link
Collaborator Author

cprussin commented Oct 27, 2018

@rnons provided an example (see #124); quoting here:

Hi, I'm trying to use httpure to write a simple backend. It's a bit strange when an error is > thrown, there is no way to see it. I have a reproducible example: https://github.com/rnons/play-with-httpure/blob/error/src/Main.purs#L13

curl http://127.0.0.1:8080 get

< HTTP/1.1 500 Internal Server Error
< Content-Length: 0
< Date: Sat, 27 Oct 2018 01:56:31 GMT
< Connection: keep-alive
<
* Connection #0 to host 127.0.0.1 left intact

Open http://127.0.0.1:8080 in browser get

This page isn’t working
localhost is currently unable to handle this request.
HTTP ERROR 500

In the terminal where I run node server.js, there is nothing. There is no error message anywhere, which makes debugging a bit difficult.

@akheron
Copy link
Collaborator

akheron commented Oct 27, 2018

We currently transform uncaught JavaScript exceptions to a 500 without any error message. Would it be better to crash the server and print the traceback to console? Would this direct users to catch errors themselves, or to use quality libraries that don't let uncaught exceptions through?

@cprussin
Copy link
Collaborator Author

@akheron I would prefer to come up with some modification to the httpure api which forces users to handle uncaught exceptions in routes. I don't think there's a way to guarantee routes themselves are exception free now that there's no row type for Effect, so I think the best approach is the always assume any route could throw and make httpure consumers tell us what to do in that case.

@akheron
Copy link
Collaborator

akheron commented Oct 27, 2018

It's not possible to ensure that JavaScript exceptions have been caught on type level. There's a plan to do something about this in Aff: purescript-contrib/purescript-aff#137

@akheron
Copy link
Collaborator

akheron commented Oct 27, 2018

... and because it's not possible on type level, I don't really see a way to enforce this other than crashing the server.

It seems to me that if the aforementioned change was made to Aff, uncaught JavaScript exceptions would more or less crash the computation. You'd have to use supervise to catch them and do something, but that wouldn't still be visible on the type level.

@cprussin
Copy link
Collaborator Author

So what I had in mind was that we would just catch all exceptions and pass them off to a user-defined handler; so essentially we would force users to write the exception handler.

But the more I think about it, the more I think you're right: if there's no enforcement on the type level, then users are no better suited to handle exceptions than we are. The fact is, if an exception occurs, the system is in an unintended and unpredictable state and should be crashed.

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

No branches or pull requests

2 participants