HeinrichApfelmus / threepenny-gui

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

Uncaught exceptions are silently discarded in 0.7.0.0 (while they are properly displayed in 0.6.0.5) #145

Closed Wizek closed 7 years ago

Wizek commented 7 years ago

Expected terminal output, as with 0.6.0.5, showing an uncaught exception:

Listening on http://127.0.0.1:8023/
[26/Oct/2016:14:06:10 +0200] Server.httpServe: START, binding to [http://127.0.0.1:8023/]
127.0.0.1 - - [26/Oct/2016:14:06:14 +0200] "GET / HTTP/1.1" 200 - - "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36"
127.0.0.1 - - [26/Oct/2016:14:06:15 +0200] "GET /haskell.css HTTP/1.1" 200 - "http://127.0.0.1:8023/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.
82 Safari/537.36"
127.0.0.1 - - [26/Oct/2016:14:06:15 +0200] "GET /haskell.js HTTP/1.1" 200 - "http://127.0.0.1:8023/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.8
2 Safari/537.36"
Test.hs: foo
Test.hs: ConnectionClosed
[26/Oct/2016:14:06:15 +0200] ["127.0.0.1"]: an exception escaped to toplevel:
ServerAppDone
127.0.0.1 - - [26/Oct/2016:14:06:15 +0200] "GET /favicon.ico HTTP/1.1" 200 - "http://127.0.0.1:8023/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.
82 Safari/537.36"

Instead, output with 0.7.0.0 is like so, no mention of the exception:

Listening on http://127.0.0.1:8023/
127.0.0.1 - - [26/Oct/2016:14:06:14 +0200] "GET / HTTP/1.1" 200 - - "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36"
127.0.0.1 - - [26/Oct/2016:14:06:15 +0200] "GET /haskell.css HTTP/1.1" 200 - "http://127.0.0.1:8023/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.
82 Safari/537.36"
127.0.0.1 - - [26/Oct/2016:14:06:15 +0200] "GET /haskell.js HTTP/1.1" 200 - "http://127.0.0.1:8023/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.8
2 Safari/537.36"

To reproduce with 0.7.0.0:

#! /usr/bin/env nix-shell
#! nix-shell -i runghc
#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-unstable.tar.gz
#! nix-shell -p 'haskellPackages.ghcWithPackages (p: [ p.threepenny-gui ] )'

import qualified Graphics.UI.Threepenny       as UI
import           Graphics.UI.Threepenny.Core

main = startGUI defaultConfig $ \w -> do
  getBody w #+ [UI.h1 # set UI.text "before error"]
  error "foo"
  getBody w #+ [UI.h1 # set UI.text "after error"]
  return ()

Put the above code in a file, make the file executable, make sure nix is installed, and execute the file. Once the server has started up, visit http://127.0.0.1:8023/ .

(Note: Nix was used so that the example above may be as self-contained as possible; however it is not strictly necessary to reproduce the issue if one makes sure (e.g. with Cabal or Stack) to use the correct version of the threepenny-gui package.)

nixos-unstable.tar.gz may be changed in the above code to nixos-15.09.tar.gz to run with threepenny-gui-0.6.0.5.

This may already be more than enough information for the issue to be identified; in case however that's not so, please let me know.

HeinrichApfelmus commented 7 years ago

Thank you for the detailed report! I think this is more than enough to reproduce the issue.

My guess is that one of the dependencies (perhaps snap or stm) has changed with regards to exceptions. Exceptions are always a bit troublesome in a multi-threaded environment or when using monad transformers.

Probably related to #143 .

HeinrichApfelmus commented 7 years ago

I think that this is a problem with the Snap framework. The latest commit mentioned here works around this quirk by printing any exception to stdout. Does this help?

Wizek commented 7 years ago

Hey @HeinrichApfelmus, I've tested it briefly, and it works like a charm! Thanks a lot for figuring out and including this workaround

I hope to test it further in the coming days and if all is well close this issue.

Wizek commented 7 years ago

@HeinrichApfelmus,

I've found another error case:

import qualified Graphics.UI.Threepenny       as UI
import           Graphics.UI.Threepenny.Core

main = startGUI defaultConfig $ \w -> do
  getBody w #+ [UI.h1 # set UI.text "before error"]
  div <- UI.div # set UI.text (error "This error should be shown")
  getBody w #+ [UI.h1 # set UI.text "after error"]
  return ()

The websocket connection gets terminated and the following is printed to stdout:

Foreign.JavaScript: Browser window disconnected.

No other detail or context is shown about the exception.

Do you think this case is also related to snapframework/snap-server#94?

Edit: Tried with both 14e78bd (2016-12-07) and 95a90ad (2016-12-10).

HeinrichApfelmus commented 7 years ago

Ah, I see, thanks a lot for the report. The problem is that this exception is from a pure value (String), which is evaluated in a different part of the code than the other exception handling code. I will fix this.

HeinrichApfelmus commented 7 years ago

I have addressed this in the most recent commit f4ac93e5d5d5ea1aa1f7a827d34a4f0f28f95e70 . Does this help?

pepeiborra commented 7 years ago

I was about to report this, good to see it is getting fixed !