@@ -57,30 +57,38 @@ runChildProcess (ChildProcess r) = r
57
57
-- | Note: some of these types are lies, and so it is unsafe to access some of
58
58
-- | these record fields directly.
59
59
type 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 )
63
63
, pid :: Int
64
64
, connected :: Boolean
65
65
, kill :: Signal -> Boolean
66
66
, send :: forall r . Fn2 { | r } Handle Boolean
67
67
, disconnect :: forall eff . Eff eff Unit
68
68
}
69
69
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
74
74
75
75
-- | The standard output stream of a child process. Note that this is only
76
76
-- | available if the process was spawned with the stdout option set to "pipe".
77
77
stdout :: forall eff . ChildProcess -> Readable () (cp :: CHILD_PROCESS | eff ) Buffer
78
- stdout = _.stdout <<< runChildProcess
78
+ stdout = unsafeFromNullable (missingStream " stdout " ) <<< _.stdout <<< runChildProcess
79
79
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
84
92
85
93
-- | The process ID of a child process. Note that if the process has already
86
94
-- | exited, another process may have taken the same ID, so be careful!
0 commit comments