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

.stream swallows errors when imagemagick not found #548

Open
bblack opened this issue Jun 30, 2016 · 5 comments
Open

.stream swallows errors when imagemagick not found #548

bblack opened this issue Jun 30, 2016 · 5 comments

Comments

@bblack
Copy link

bblack commented Jun 30, 2016

still digging into this, but it seems that on e.g.

gm(readStream)
.resize(w, h)
.stream('png', function(err, stdout){
  // no err; stdout is zero-length
});

no error is reported. it seems that the callback cb in lib/command.js is being called 3 times, and the first time is not passed the error. will add more specifics as i have them.

@bblack bblack changed the title error is swallowed when imagemagick not found .stream swallows errors when imagemagick not found Jun 30, 2016
@bblack
Copy link
Author

bblack commented Jun 30, 2016

it looks like on streaming, the _spawn function explicitly calls the callback immediately. what's the best way to fix this? here are some options:

  • wait for the process to exit before calling the callback. largely defeats the purpose of a streaming option.
  • emit the error so it can be caught. basically allows the gives the caller the ability to do the above. e.g.
gm(ReadStream)
.resize(w, h)
.stream('png', function(err, stdout){
})
.on('error', function(){ ... });
  • do more. since we're trying to be clever by emitting errors, and failing, try to be even cleverer by intercepting errors before allowing the stdout stream that's passed to the callback emit end. (probably a terrible idea).
  • do less. remove the .stream method entirely, and instead just expose the proc object returned by child_process.spawn. probably makes the most sense, since we're already exposing the stdout and sterr streams directly. e.g.
gm(readStream)
.resize(w, h)
.proc('png'); // this is a proc, and i get all the errors and stdout and stderr

@paulmelnikow
Copy link

Would love to see this fixed. This comes up for users of the badges CLI as well as developers – see badges/shields#883.

These two seem like the workable options:

  • emit the error so it can be caught. basically allows the gives the caller the ability to do the above. e.g.

If we did this, we could also add an .on('close') event.

  • do less. remove the .stream method entirely, and instead just expose the proc object returned by child_process.spawn. probably makes the most sense, since we're already exposing the stdout and sterr streams directly. e.g.

This makes sense too.

Would it make sense to offer both?

@bblack Are you still using this? If I put a patch together would you like to give it a look?

@bblack
Copy link
Author

bblack commented Mar 28, 2017

Are you still using this?

Yes!

If I put a patch together would you like to give it a look?

That would be great, although I make no guarantee about when.

@paulmelnikow
Copy link

Hrm, just noticed this was previously reported at #256.

@paulmelnikow
Copy link

Exposing the proc object synchronously is difficult, because the preprocessors are first invoked in series. Though it's easy enough to expose it in the callback, as suggested in #256.

Would you like to close this and continue there?

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

No branches or pull requests

2 participants