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

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

Closed
Wizek opened this issue Nov 8, 2016 · 7 comments

Comments

@Wizek
Copy link

Wizek commented Nov 8, 2016

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
Copy link
Owner

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
Copy link
Owner

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
Copy link
Author

Wizek commented Dec 7, 2016

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
Copy link
Author

Wizek commented Dec 12, 2016

@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
Copy link
Owner

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 added a commit that referenced this issue Mar 27, 2017
The API may be called in ways where pure values
contain exceptions, e.g.

	element div # set UI.text (error “oops”)

This call will be translated into a message for
the JavaScript side. Sending this message will
fail, because it contains a _|_ value.
We now try to force this exception in the
translation phase, because this will result in a
better error message.
@HeinrichApfelmus
Copy link
Owner

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

@pepeiborra
Copy link
Contributor

pepeiborra commented Apr 28, 2017

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

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

No branches or pull requests

3 participants