From cd5245b79e7cc2cf85685418df6ffe2a5d3a6fb4 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 20 Jul 2023 06:05:23 -0700 Subject: [PATCH] Migrate error to system error --- CHANGELOG.md | 1 + bower.json | 1 + src/Node/ChildProcess.purs | 17 ++--------------- test/Main.purs | 3 ++- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a02af7..7b61503 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/bower.json b/bower.json index b1069ab..2239f0f 100644 --- a/bower.json +++ b/bower.json @@ -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" diff --git a/src/Node/ChildProcess.purs b/src/Node/ChildProcess.purs index 3f9696d..3e90a4b 100644 --- a/src/Node/ChildProcess.purs +++ b/src/Node/ChildProcess.purs @@ -34,8 +34,6 @@ module Node.ChildProcess , killed , signalCode , send - , Error - , toStandardError , Exit(..) , spawn , SpawnOptions @@ -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 @@ -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) @@ -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. -- | diff --git a/test/Main.purs b/test/Main.purs index 23ee033..a61c408 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -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) @@ -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