-
Notifications
You must be signed in to change notification settings - Fork 15
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
don't break when stderr is used #3
base: master
Are you sure you want to change the base?
Conversation
df using stderr does not mean the command failed. for example, on heroku, using `df` fails: ```shell $ df; echo $? df: cannot read table of mounted file systems: No such file or directory 1 ``` but using `df /app` works with a warning: ```shell $ df /app; echo $? df: Warning: cannot read table of mounted file systems: No such file or directory Filesystem 1K-blocks Used Available Use% Mounted on - 12345 123 1234 123% /app 0 ``` This change first checks if there is an error, and then sets the error's message to whatever stderr is. It will always call back with the error or stderr only, and with the parsed info from stdout. However, it will always try to parse, even if stderr is used or an error occured That makes it possible to use node-df on systems like heroku where df prints warnings to stderr, but works anyway
I think I forgot something, don't merge this yet :P 💩 |
nvm, works exactly as intended 😎 df({}, function(err, result) {
console.error("Error", err);
console.log(result);
});
//=> error { [Error: df: cannot read table of mounted file systems: No such file or directory
// ] killed: false, code: 1, signal: null, cmd: '/bin/sh -c df -kP' }
//=> undefined df({file: "/app"/}, function(err, result) {
console.error("Error", err);
console.log(result);
});
//=> error df: Warning: cannot read table of mounted file systems: No such file or directory
//=> [ { filesystem: '-',
// size: 12345,
// used: 123,
// available: 1234,
// capacity: 123,
// mount: '/app' } ] |
until adriano-di-giovanni/node-df#3 is merged fixes #4
Hi @jomo, Can you tell me about line 21 if (error) { error.message = stderr; } I think that |
You're right. |
I mean, you can have |
Yes, that's where callback(error || stderr, response); kicks in. |
df
printing to stderr does not mean the command failed.for example, on heroku, using
df
fails:but using
df /app
works with a warning:This change first checks if there is an error, and then sets the error's message to whatever stderr is.
It will always call back with the error or stderr only, and with the parsed info from stdout.
However, it will always try to parse, even if stderr is used or an error occured
That makes it possible to use node-df on systems like heroku where df prints warnings to stderr, but works anyway