Parallel requests and Exception handling
Opened this issue · 7 comments
The program below logs the error when using 4.0.0, but when I upgrade to 5.0.0 it no longer logs the error
module Main where
import Prelude
import Control.Monad.Aff (Aff, launchAff)
import Control.Monad.Aff.Console (log, logShow)
import Control.Monad.Eff.Exception (EXCEPTION, error)
import Control.Monad.Error.Class (throwError, try)
import Control.Parallel (parallel, sequential)
import Data.Tuple (Tuple(..))
import Network.HTTP.Affjax (AJAX, get)
getPostbin :: forall eff. Aff (exception :: EXCEPTION, ajax :: AJAX | eff) String
getPostbin = do
resp <- get "http://postb.in/BgIt83CL"
void $ throwError (error "Oops")
pure resp.response
main = void $ launchAff do
t <- try $ sequential $ Tuple <$> parallel getPostbin <*> parallel getPostbin
logShow t
Is it the "Oops" error you're expecting to see? This is down to a change in Aff
rather than affjax
, and I think it may be intentional. /cc @natefaubion
Yeah, I'd like to catch the oops error. If I just do a delay
instead of the get
I can catch the error, so that's why I kinda assumed it would be an issue with affjax
.
Hmm maybe you're right then! I just took a look at the diff between v4 and v5, and although it's "just" the aff update it wasn't entirely straight forward.
can you see the error if you do main = runAff_ log do ...
?
Unfortunately it's still not showing with that change
This is probably #112. When running things in parallel, if one throws an exception the runtime will cancel the other fibers. However cancellation is broken, and so the canceller never yields, hanging it.
@natefaubion as per #117 (comment), with a fixed canceller this is still broken, but definitely seems to be in Aff
now:
purescript-affjax\output\Effect.Aff\foreign.js:83
throw error;
^
TypeError: Cannot read property 'constructor' of null
at Object.isLeft (purescript-affjax\output\Effect.Aff\index.js:76:112)
at join (purescript-affjax\output\Effect.Aff\foreign.js:720:16)
at purescript-affjax\output\Effect.Aff\foreign.js:778:19
at purescript-affjax\output\Effect.Aff\foreign.js:669:29
at runEff (purescript-affjax\output\Effect.Aff\foreign.js:80:7)
at run (purescript-affjax\output\Effect.Aff\foreign.js:496:15)
at purescript-affjax\output\Effect.Aff\foreign.js:333:19
at drain (purescript-affjax\output\Effect.Aff\foreign.js:120:9)
at Object.enqueue (purescript-affjax\output\Effect.Aff\foreign.js:141:11)
at purescript-affjax\output\Effect.Aff\foreign.js:330:27
Should we open an issue there?