Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jomo
Copy link

@jomo jomo commented Aug 30, 2015

df printing to stderr does not mean the command failed.

for example, on heroku, using df fails:

$ df; echo $?
df: cannot read table of mounted file systems: No such file or directory
1

but using df /app works with a warning:

$ 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

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
@jomo
Copy link
Author

jomo commented Aug 30, 2015

I think I forgot something, don't merge this yet :P 💩

@jomo
Copy link
Author

jomo commented Aug 30, 2015

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' } ]

jomo added a commit to crafatar/crafatar that referenced this pull request Aug 30, 2015
@adriano-di-giovanni
Copy link
Owner

Hi @jomo,
and thanks for your contribution.

Can you tell me about line 21

if (error) { error.message = stderr; }

I think that error and stderr aren't interrelated. Are they?
I mean, you can have stderr without error and maybe error without stderr.

@jomo
Copy link
Author

jomo commented Aug 31, 2015

You're right.
The error has no message by default, so if there is something in stderr it might provide more information about the error.

@adriano-di-giovanni
Copy link
Owner

I mean, you can have error === null and stderr !== null and viceversa.

@jomo
Copy link
Author

jomo commented Sep 2, 2015

Yes, that's where

callback(error || stderr, response);

kicks in.
If there is an error, it will include stderr, otherwise it's just stderr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants