Code Monkey home page Code Monkey logo

duplex-child-process's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

duplex-child-process's Issues

Fail error: "list" argument must be an Array of Buffers

It looks like the response is unexpected so it's crashing. Also not sure what's going on with the negative 2 exit code from the command I'm trying to run.

buffer.js:296
    throw new TypeError('"list" argument must be an Array of Buffers');
    ^

TypeError: "list" argument must be an Array of Buffers
    at Function.Buffer.concat (buffer.js:296:11)
    at ChildProcess.onExit (/var/app/current/node_modules/duplex-child-process/index.js:123:50)
    at ChildProcess.g (events.js:291:16)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:877:16)
    at Socket.<anonymous> (internal/child_process.js:334:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at Pipe._handle.close [as _onclose] (net.js:498:12)

I output the contents of stderr, code, and signal variables to console to help troubleshoot:

stderr:
null
code:
-2
signal:
null

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

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()
  }

moar testes

  • kill
  • pipes should work before spawning
  • a constructor should be reusable if Wrapper.call(this) again

Chunks are not preserved.

I have this small js script.

const childProcess = require('duplex-child-process');
const { Readable, Transform } = require('stream');

const reader = new Readable({
    encoding: 'utf-8',
});

const transformer = new Transform({
    transform: (chunk, encoding, callback) => {
        console.log('chunk:', chunk.toString());
        callback(null, chunk);
    }
});

reader
  .pipe(childProcess.spawn('./hellowolrd.py'))
  .pipe(transformer)

reader.push('This is a test.\n');
reader.push('This is a test.\n');
reader.push('This is a test.\n');
reader.push(null);

It calls this small python script that just write stdin to sdout.

#!/usr/bin/env python3
import sys

def main():
    for line in sys.stdin:
        sys.stdout.write(line)

if __name__ == '__main__':
    main()

I'm expecting to have this result:

chunk: This is a test.
chunk: This is a test.
chunk: This is a test.

But I have this:

chunk: This is a test.
This is a test.
This is a test.

It seems that chunks are concatenated before being sent to the next stream.
Is this normal behaviour ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.