HeinrichApfelmus / threepenny-gui

GUI framework that uses the web browser as a display.
https://heinrichapfelmus.github.io/threepenny-gui/
Other
437 stars 77 forks source link

Exceptions in the UI monad silently cause the web socket connection to be closed #143

Closed kaoskorobase closed 7 years ago

kaoskorobase commented 7 years ago

Exceptions raised in the UI monad, e.g. via fail or liftIO . throwIO seem to silently interrupt the web socket connection with a 1006 error code (in Chrome on OSX with threepenny-gui version 0.7.0.0). This can be reproduced by raising an exception in the setup function or in an event handler.

For example the following setup function

setup :: Window -> UI ()
setup _ = do
  liftIO . putStrLn $ "Hello!"
  liftIO . throwIO $ userError "BAM!"
  liftIO . putStrLn $ "Goodbye!"

Produces:

Listening on http://127.0.0.1:8023
127.0.0.1 - - [07/Oct/2016:15:51:01 +0200] "GET / HTTP/1.1" 200 440 - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36"
127.0.0.1 - - [07/Oct/2016:15:51:02 +0200] "GET /haskell.js HTTP/1.1" 200 99184 "http://127.0.0.1:8023/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36"
Hello!
127.0.0.1 - - [07/Oct/2016:15:51:02 +0200] "GET /favicon.ico HTTP/1.1" 200 440 "http://127.0.0.1:8023/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36"

It would be useful for debugging to at least print uncaught exceptions and errors to the console or even to terminate the application.

Possibly related to #129.

HeinrichApfelmus commented 7 years ago

The latest commit should hopefully fix this. This bug is the same as #145 . I'm closing this one, and would like to refer you to the other instance for further discussion. ✈️

EDIT: And thank you nonetheless for reporting it in the first place, of course!