Skip to content

Migrate error to system error #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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