polotek / procstreams

220 stars 19 forks source link

"Invalid command" on node 0.8 #16

Closed max-mapper closed 11 years ago

max-mapper commented 11 years ago

not sure what i'm doin wrong

require('procstreams')('ls').pipe(process.stdout)

results in:

Error: Invalid command
    at normalizeArguments (/Users/maxogden/src/node-mdb/node_modules/procstreams/procstreams.js:84:11)
    at procStream (/Users/maxogden/src/node-mdb/node_modules/procstreams/procstreams.js:115:7)
    at procStream._prototype.pipe (/Users/maxogden/src/node-mdb/node_modules/procstreams/procstreams.js:244:25)
    at repl:1:10
    at REPLServer.self.eval (repl.js:111:21)
    at Interface.<anonymous> (repl.js:250:12)
    at Interface.EventEmitter.emit (events.js:88:17)
    at Interface._onLine (readline.js:183:10)
    at Interface._line (readline.js:502:8)
    at Interface._ttyWrite (readline.js:720:14)
max-mapper commented 11 years ago

ahh yeah heres the test suite output:

pizzacats:procstreams maxogden$ npm test

> procstreams@0.2.0 test /Users/maxogden/src/node-mdb/node_modules/procstreams
> tests/run_tests.sh

tests/test-arguments.js

assert.js:104
  throw new assert.AssertionError({
        ^
AssertionError: "v0.8.0" == ""
    at procStream.<anonymous> (/Users/maxogden/src/node-mdb/node_modules/procstreams/tests/test-arguments.js:16:14)
    at procStream.EventEmitter.emit (events.js:98:17)
    at procStream.<anonymous> (/Users/maxogden/src/node-mdb/node_modules/procstreams/procstreams.js:105:10)
    at procStream.EventEmitter.emit (events.js:115:20)
    at Process._handle.onexit (child_process.js:674:10)
------
tests/test-error.js
------
tests/test-methods.js
------
tests/test-operators.js

assert.js:104
  throw new assert.AssertionError({
        ^
AssertionError: "pass2" == ""
    at procStream.<anonymous> (/Users/maxogden/src/node-mdb/node_modules/procstreams/tests/test-operators.js:56:16)
    at procStream.EventEmitter.emit (events.js:98:17)
    at procStream.<anonymous> (/Users/maxogden/src/node-mdb/node_modules/procstreams/procstreams.js:105:10)
    at procStream.EventEmitter.emit (events.js:91:17)
    at Process._handle.onexit (child_process.js:674:10)
------
tests/test-pipe.js

assert.js:104
  throw new assert.AssertionError({
        ^
AssertionError: "3" == ""
    at procStream.<anonymous> (/Users/maxogden/src/node-mdb/node_modules/procstreams/tests/test-pipe.js:14:14)
    at procStream.EventEmitter.emit (events.js:98:17)
    at procStream.<anonymous> (/Users/maxogden/src/node-mdb/node_modules/procstreams/procstreams.js:105:10)
    at procStream.EventEmitter.emit (events.js:115:20)
    at Process._handle.onexit (child_process.js:674:10)
------
tests/test-promises.js
three

assert.js:104
  throw new assert.AssertionError({
        ^
AssertionError: "three" == ""
    at procStream.<anonymous> (/Users/maxogden/src/node-mdb/node_modules/procstreams/tests/test-promises.js:15:14)
    at procStream.EventEmitter.emit (events.js:98:17)
    at procStream.<anonymous> (/Users/maxogden/src/node-mdb/node_modules/procstreams/procstreams.js:105:10)
    at procStream.EventEmitter.emit (events.js:91:17)
    at Process._handle.onexit (child_process.js:674:10)
------
tests/test-simple.js
------

4 tests failed
max-mapper commented 11 years ago

so it looks like when you call pipe on a procstream it hits this code path:

https://github.com/polotek/procstreams/blob/master/procstreams.js#L244

which then calls the procStream(cmd, args, opts, callback) function again but with cmd set to a stream

inside normalizeArguments it only wants cmd to be a string or array so it throws the invalid command error. why is it calling procStream with cmd set to a stream?

max-mapper commented 11 years ago

oh I think i'm misunderstanding this module

max-mapper commented 11 years ago

I found this easier FWIW: https://github.com/maxogden/node-mdb/commit/a6f425ed8045fd294cd1579327149b0996945533#L0L15

polotek commented 11 years ago

Yeah the api has definitely not achieved it's goal of being nicer than the core api in most respects. I haven't really updated it in a long time.

polotek commented 11 years ago

The problem with this is that you're trying to pass a stream instead of a proc or a proc command. I'm going to add support for piping to streams. It's less than trivial if we want to support piping from a stream into a procstream. Because we have to override the default pipe method and still have things act sensibly. For now, I've at least added a more sensible error message.

polotek commented 11 years ago

Okay this should be fixed. Procs should be mostly compatible with normal streams, so you can pipe back and forth between them. I'm doing a release soon. If you use it again, let me know how it works. Also take a look at the api. the out() and data() methods cover most people use cases for getting output.