tweag/asterius

confusing Uncaught (in promise) JSException

whirlicote opened this issue · 0 comments

Describe the bug
I get a confusing error message. I cannot grasp what went wrong or what failed.

To Reproduce
In order to reproduce this error message compile and execute this code:

import Asterius.Types

main :: IO ()
main = do
  first_heartbeat

first_heartbeat :: IO ()
first_heartbeat = heartbeat 100000000

heartbeat 0 = return ()
heartbeat n = do
  maintenance_chore
  javaScript_setTimeout_2parameter 3 (heartbeat $ n-1)

maintenance_chore :: IO ()
maintenance_chore = do
  javaScript_putStr "higgs boson"

javaScript_setTimeout_2parameter :: Int -> IO () -> IO ()
javaScript_setTimeout_2parameter delay callback = do
  javaScript_function <- javaScriptHaskell_makeCallback0 callback
  javaScriptHaskell_setTimeout_2parameter javaScript_function delay

javaScript_putStr :: String -> IO ()
javaScript_putStr = javaScriptHaskell_console_log . toJSString

foreign import javascript
  "wrapper"
  javaScriptHaskell_makeCallback0
  :: (IO ()) -> IO JSFunction

foreign import javascript
  "setTimeout($1,$2)"
  javaScriptHaskell_setTimeout_2parameter
  :: JSFunction -> Int -> IO ()

foreign import javascript "console.log($1)"
  javaScriptHaskell_console_log
  :: JSString -> IO ()

This leads to an Uncaught (in promise) JSException with:

barf@http://localhost:3000/rts.exception.mjs:140:13
@http://localhost:3000/Hilbert.wasm:wasm-function[92]:0x6b62
@http://localhost:3000/Hilbert.wasm:wasm-function[2511]:0x75b0c
@http://localhost:3000/Hilbert.wasm:wasm-function[2502]:0x758a3
@http://localhost:3000/Hilbert.wasm:wasm-function[2503]:0x758d0
tick@http://localhost:3000/rts.scheduler.mjs:347:22
enqueueTSO/<@http://localhost:3000/rts.scheduler.mjs:382:29
run@http://localhost:3000/rts.setimmediate.mjs:46:11
runIfPresent@http://localhost:3000/rts.setimmediate.mjs:75:22
onGlobalMessage@http://localhost:3000/rts.setimmediate.mjs:115:27
EventListener.handleEvent*installPostMessageImplementation@http://localhost:3000/rts.setimmediate.mjs:120:18
@http://localhost:3000/rts.setimmediate.mjs:175:7
@http://localhost:3000/rts.setimmediate.mjs:192:2

Expected behavior
I would expect to have some information in the error message that points to some location so that I can further investigate the issue.

Environment

  • docker image 5a3d9d0d0f0c for compiling
  • Mozilla Firefox 91.0.2

Additional context
I used the Hilbert example setup and adapted it to the code above. I am trying to write something similar to the javascript eventloop.