Skip to content

TypeError: cb is not a function when child exits with error #13

Description

@aalexgabi

I'm using Child_Process like this:

await pipeline([
  got.stream(url),
  DuplexChildProcess.spawn('convert', convertArgs),
  DuplexChildProcess.spawn('pngquant', quantArgs),
  ...
])

If pngquant command fails I have an unhandled error:

/home/.../node_modules/duplex-child-process/index.js:146
    cb && cb()
          ^

TypeError: cb is not a function
    at Child_Process.kill (/home/.../node_modules/duplex-child-process/index.js:146:11)
    at internal/streams/pipeline.js:47:61
    at internal/streams/pipeline.js:83:11
    at internal/util.js:392:14
    at Child_Process.<anonymous> (internal/streams/pipeline.js:33:21)
    at Child_Process.<anonymous> (internal/util.js:392:14)
    at Child_Process.onerror (internal/streams/end-of-stream.js:54:14)
    at Child_Process.emit (events.js:321:20)
    at ChildProcess.onExit (/home/.../node_modules/duplex-child-process/index.js:119:12)
    at Object.onceWrapper (events.js:428:26)
    at ChildProcess.emit (events.js:321:20)
    at maybeClose (internal/child_process.js:1026:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)

readable.destroy() and writable.destroy() expect an error argument: https://nodejs.org/api/stream.html#stream_readable_destroy_error

But Child_Process sets this function for destroy method:

this.kill = this.destroy = kill

And this function expects a cb:

  function kill(cb) {
    that._stdout.destroy()
    that._stderr.destroy()

    killed = true

    try {
      that._process.kill((options && options.killSignal) || 'SIGTERM')
    } catch (e) {
      ex = e
      onExit()
    }
    console.log('cb', cb, new Error().stack)
    cb && cb()
  }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions