Skip to content

Commit

Permalink
Migrate error to system error (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanMartinez authored Jul 20, 2023
1 parent 13fa204 commit dd7dd01
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Breaking changes:
See https://pursuit.purescript.org/packages/purescript-node-event-emitter/3.0.0/docs/Node.EventEmitter for more details.
- Update `pid` type signature to return `Maybe Pid` rather than `Pid` (#44 by @JordanMartinez)
- Update `kill` returned value from `Effect Unit` to `Effect Boolean` (#44 by @JordanMartinez)
- Migrate `Error` to `node-os`' `SystemError` (#45 by @JordanMartinez)


New features:
Expand Down
1 change: 1 addition & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"purescript-functions": "^6.0.0",
"purescript-node-fs": "^9.0.0",
"purescript-node-streams": "^8.0.0",
"purescript-node-os": "v5.1.0",
"purescript-nullable": "^6.0.0",
"purescript-posix-types": "^6.0.0",
"purescript-unsafe-coerce": "^6.0.0"
Expand Down
17 changes: 2 additions & 15 deletions src/Node/ChildProcess.purs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ module Node.ChildProcess
, killed
, signalCode
, send
, Error
, toStandardError
, Exit(..)
, spawn
, SpawnOptions
Expand Down Expand Up @@ -71,6 +69,7 @@ import Foreign (Foreign)
import Foreign.Object (Object)
import Node.Buffer (Buffer)
import Node.Encoding (Encoding, encodingToNode)
import Node.Errors.SystemError (SystemError)
import Node.EventEmitter (EventEmitter, EventHandle(..))
import Node.EventEmitter.UtilTypes (EventHandle0, EventHandle1)
import Node.FS as FS
Expand Down Expand Up @@ -100,7 +99,7 @@ closeH = EventHandle "close" \cb -> mkEffectFn2 \code signal ->
disconnectH :: EventHandle0 ChildProcess
disconnectH = EventHandle "disconnect" identity

errorH :: EventHandle1 ChildProcess Error
errorH :: EventHandle1 ChildProcess SystemError
errorH = EventHandle "error" mkEffectFn1

exitH :: EventHandle ChildProcess (Exit -> Effect Unit) (EffectFn2 (Nullable Int) (Nullable String) Unit)
Expand Down Expand Up @@ -472,18 +471,6 @@ foreign import fork
-> Array String
-> Effect ChildProcess

-- | An error which occurred inside a child process.
type Error =
{ code :: String
, errno :: String
, syscall :: String
}

-- | Convert a ChildProcess.Error to a standard Error, which can then be thrown
-- | inside an Effect or Aff computation (for example).
toStandardError :: Error -> Exception.Error
toStandardError = unsafeCoerce

-- | Behaviour for standard IO streams (eg, standard input, standard output) of
-- | a child process.
-- |
Expand Down
3 changes: 2 additions & 1 deletion test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Node.Buffer as Buffer
import Node.ChildProcess (Exit(..), defaultExecOptions, defaultExecSyncOptions, defaultSpawnOptions, errorH, exec, execSync, exitH, kill, spawn, stdout)
import Node.Encoding (Encoding(UTF8))
import Node.Encoding as NE
import Node.Errors.SystemError (code)
import Node.EventEmitter (on_)
import Node.Stream (dataH)

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

execLs :: Effect Unit
execLs = do
Expand Down

0 comments on commit dd7dd01

Please sign in to comment.