Skip to content

Commit dd7dd01

Browse files
Migrate error to system error (#45)
1 parent 13fa204 commit dd7dd01

File tree

4 files changed

+6
-16
lines changed

4 files changed

+6
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Breaking changes:
2121
See https://pursuit.purescript.org/packages/purescript-node-event-emitter/3.0.0/docs/Node.EventEmitter for more details.
2222
- Update `pid` type signature to return `Maybe Pid` rather than `Pid` (#44 by @JordanMartinez)
2323
- Update `kill` returned value from `Effect Unit` to `Effect Boolean` (#44 by @JordanMartinez)
24+
- Migrate `Error` to `node-os`' `SystemError` (#45 by @JordanMartinez)
2425

2526

2627
New features:

bower.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"purescript-functions": "^6.0.0",
2424
"purescript-node-fs": "^9.0.0",
2525
"purescript-node-streams": "^8.0.0",
26+
"purescript-node-os": "v5.1.0",
2627
"purescript-nullable": "^6.0.0",
2728
"purescript-posix-types": "^6.0.0",
2829
"purescript-unsafe-coerce": "^6.0.0"

src/Node/ChildProcess.purs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ module Node.ChildProcess
3434
, killed
3535
, signalCode
3636
, send
37-
, Error
38-
, toStandardError
3937
, Exit(..)
4038
, spawn
4139
, SpawnOptions
@@ -71,6 +69,7 @@ import Foreign (Foreign)
7169
import Foreign.Object (Object)
7270
import Node.Buffer (Buffer)
7371
import Node.Encoding (Encoding, encodingToNode)
72+
import Node.Errors.SystemError (SystemError)
7473
import Node.EventEmitter (EventEmitter, EventHandle(..))
7574
import Node.EventEmitter.UtilTypes (EventHandle0, EventHandle1)
7675
import Node.FS as FS
@@ -100,7 +99,7 @@ closeH = EventHandle "close" \cb -> mkEffectFn2 \code signal ->
10099
disconnectH :: EventHandle0 ChildProcess
101100
disconnectH = EventHandle "disconnect" identity
102101

103-
errorH :: EventHandle1 ChildProcess Error
102+
errorH :: EventHandle1 ChildProcess SystemError
104103
errorH = EventHandle "error" mkEffectFn1
105104

106105
exitH :: EventHandle ChildProcess (Exit -> Effect Unit) (EffectFn2 (Nullable Int) (Nullable String) Unit)
@@ -472,18 +471,6 @@ foreign import fork
472471
-> Array String
473472
-> Effect ChildProcess
474473

475-
-- | An error which occurred inside a child process.
476-
type Error =
477-
{ code :: String
478-
, errno :: String
479-
, syscall :: String
480-
}
481-
482-
-- | Convert a ChildProcess.Error to a standard Error, which can then be thrown
483-
-- | inside an Effect or Aff computation (for example).
484-
toStandardError :: Error -> Exception.Error
485-
toStandardError = unsafeCoerce
486-
487474
-- | Behaviour for standard IO streams (eg, standard input, standard output) of
488475
-- | a child process.
489476
-- |

test/Main.purs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Node.Buffer as Buffer
1010
import Node.ChildProcess (Exit(..), defaultExecOptions, defaultExecSyncOptions, defaultSpawnOptions, errorH, exec, execSync, exitH, kill, spawn, stdout)
1111
import Node.Encoding (Encoding(UTF8))
1212
import Node.Encoding as NE
13+
import Node.Errors.SystemError (code)
1314
import Node.EventEmitter (on_)
1415
import Node.Stream (dataH)
1516

@@ -56,7 +57,7 @@ nonExistentExecutable :: Effect Unit -> Effect Unit
5657
nonExistentExecutable done = do
5758
ch <- spawn "this-does-not-exist" [] defaultSpawnOptions
5859
ch # on_ errorH \err ->
59-
log err.code *> done
60+
log (code err) *> done
6061

6162
execLs :: Effect Unit
6263
execLs = do

0 commit comments

Comments
 (0)