@@ -57,30 +57,38 @@ runChildProcess (ChildProcess r) = r
5757-- | Note: some of these types are lies, and so it is unsafe to access some of
5858-- | these record fields directly.
5959type ChildProcessRec =
60- { stderr :: forall eff . Readable ( ) (cp :: CHILD_PROCESS | eff ) Buffer
61- , stdin :: forall eff . Writable ( ) (cp :: CHILD_PROCESS | eff ) Buffer
62- , stdout :: forall eff . Readable () (cp :: CHILD_PROCESS | eff ) Buffer
60+ { stdin :: forall eff . Nullable ( Writable ( ) (cp :: CHILD_PROCESS | eff ) Buffer )
61+ , stdout :: forall eff . Nullable ( Readable ( ) (cp :: CHILD_PROCESS | eff ) Buffer )
62+ , stderr :: forall eff . Nullable ( Readable () (cp :: CHILD_PROCESS | eff ) Buffer )
6363 , pid :: Int
6464 , connected :: Boolean
6565 , kill :: Signal -> Boolean
6666 , send :: forall r . Fn2 { | r } Handle Boolean
6767 , disconnect :: forall eff . Eff eff Unit
6868 }
6969
70- -- | The standard error stream of a child process. Note that this is only
71- -- | available if the process was spawned with the stderr option set to "pipe".
72- stderr :: forall eff . ChildProcess -> Readable () (cp :: CHILD_PROCESS | eff ) Buffer
73- stderr = _.stderr <<< runChildProcess
70+ -- | The standard input stream of a child process. Note that this is only
71+ -- | available if the process was spawned with the stdin option set to "pipe".
72+ stdin :: forall eff . ChildProcess -> Writable () (cp :: CHILD_PROCESS | eff ) Buffer
73+ stdin = unsafeFromNullable (missingStream " stdin " ) <<< _.stdin <<< runChildProcess
7474
7575-- | The standard output stream of a child process. Note that this is only
7676-- | available if the process was spawned with the stdout option set to "pipe".
7777stdout :: forall eff . ChildProcess -> Readable () (cp :: CHILD_PROCESS | eff ) Buffer
78- stdout = _.stdout <<< runChildProcess
78+ stdout = unsafeFromNullable (missingStream " stdout " ) <<< _.stdout <<< runChildProcess
7979
80- -- | The standard input stream of a child process. Note that this is only
81- -- | available if the process was spawned with the stdin option set to "pipe".
82- stdin :: forall eff . ChildProcess -> Writable () (cp :: CHILD_PROCESS | eff ) Buffer
83- stdin = _.stdin <<< runChildProcess
80+ -- | The standard error stream of a child process. Note that this is only
81+ -- | available if the process was spawned with the stderr option set to "pipe".
82+ stderr :: forall eff . ChildProcess -> Readable () (cp :: CHILD_PROCESS | eff ) Buffer
83+ stderr = unsafeFromNullable (missingStream " stderr" ) <<< _.stderr <<< runChildProcess
84+
85+ missingStream :: String -> String
86+ missingStream str =
87+ " Node.ChildProcess: stream not available: " <> str <> " \n This is probably "
88+ <> " because you passed something other than Pipe to the stdio option when "
89+ <> " you spawned it."
90+
91+ foreign import unsafeFromNullable :: forall a . String -> Nullable a -> a
8492
8593-- | The process ID of a child process. Note that if the process has already
8694-- | exited, another process may have taken the same ID, so be careful!
0 commit comments