I would expect to see the full error message - something along the lines of:
mkdir: cannot create directory 'abc': File exists
However, the error that is seen is simply this:
mkdir:
And on top of that, the data type of the error is Buffer instead of string as one would expect.
The issue arises because of the way stderr output is handled. Any time that stdout output is received, it is put into a 'buffer', which is actually just a string, and then when the stream is closed, the buffer is returned. With stderr output, the code immediately rejects the promise with the received chunk of data (which is of type Buffer - not string), and so the output is of an inconsistent type, and it is also incomplete in content. I propose the following fix:
Mark the operation as a failure upon receiving the first bit of output from stderr, but do not reject immediately. Instead, push the output into a second buffer which is for error output only. After the connection closes, we can call reject(errorBuffer) if any stderr output came through to reject the promise with the full output instead of only partial output. Additionally, this will fix the issue of inconsistent data types, because the error buffer will always be a string.
I am willing to fork and write a PR for this change, as I've already explored the code for it.
With a command such as the following:
I would expect to see the full error message - something along the lines of:
However, the error that is seen is simply this:
And on top of that, the data type of the error is
Buffer
instead ofstring
as one would expect.The issue arises because of the way
stderr
output is handled. Any time thatstdout
output is received, it is put into a 'buffer', which is actually just a string, and then when the stream is closed, the buffer is returned. Withstderr
output, the code immediately rejects the promise with the received chunk of data (which is of typeBuffer
- notstring
), and so the output is of an inconsistent type, and it is also incomplete in content. I propose the following fix:Mark the operation as a failure upon receiving the first bit of output from
stderr
, but do not reject immediately. Instead, push the output into a second buffer which is for error output only. After the connection closes, we can callreject(errorBuffer)
if anystderr
output came through to reject the promise with the full output instead of only partial output. Additionally, this will fix the issue of inconsistent data types, because the error buffer will always be a string.I am willing to fork and write a PR for this change, as I've already explored the code for it.