Skip to content

Is printing to stdout swallowed mistakenly when running with debug in ghcid? #48

@Wizek

Description

@Wizek

If I have a Main.hs like so:

import            Control.Monad.IO.Class
import            Language.Javascript.JSaddle
import            Language.Javascript.JSaddle.Warp

main = do
  liftIO $ print 1
  debug 3197 $ do
    liftIO $ print 2
    eval $ textToStr "document.write('3')"
    liftIO $ print 4

And run

$ nix-shell -p 'haskell.packages.ghc822.ghcWithPackages (p: with p; [(haskell.lib.dontCheck jsaddle-warp)])' -p haskellPackages.ghcid -j4 --run 'ghcid Main.hs -T main'

Then navigate to http://localhost:3197

On stdout, I'd hope to see:

1
<a href="http://localhost:3197">run</a>
2
4

And instead I only see

1
<a href="http://localhost:3197">run</a>
<interactive>: threadWait: invalid argument (Bad file descriptor)

If I change to

import            Control.Concurrent
import            Control.Monad.IO.Class
import            Language.Javascript.JSaddle
import            Language.Javascript.JSaddle.Warp

main = do
  liftIO $ print 1
  debug 3197 $ do
    liftIO $ print 2
    eval $ textToStr "document.write('3')"
    liftIO $ print 4

  threadDelay $ 1000 * 1000 * 5

Then I'll see a bit more:

1
<a href="http://localhost:3197">run</a>
<interactive>: threadWait: invalid argument (Bad file descriptor)
2
4

But surely the delay is counterintuitive and shouldn't be necessary, right?

Could fixing it perhaps be as simple as having a variant of debug that doesn't forkIO inside? As GHCid issues an interrupt anyway.

Could I try such a variant easily somehow? Looking at the source here it's not immediately apparent to me how to make a non-forking variant unfortunately.

And yet another unfortunate attribute is that in a larger codebase of mine (which I am attempting to port over to use JSaddle) I can't even seem to use the threadDelay workaround. One thing or another causes ghc(i(d)) to hang on "Reloading..." when I do that. Meaning that currently, seemingly I have to choose between being able to see stdoutput during development or being able to do auto-refresh. Both of which I find rather important to have at the same time.
This I haven't been able to narrow down to such a small reproducible case as above yet, so my current hope is that if we fix the above error in general and make JSaddle.debug + ghcid + stdout work together nicely then this error will vaporize too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions