Error when pygments not installed #6
Comments
Are you sure? https://github.com/pksunkara/pygments.js/blob/master/pygments.js#L44 makes sure the error returned in the callback. |
@pksunkara Not sure if that link is to the wrong line, but it definitely doesn't error check. If pygments isn't installed, the following line will throw: pyg.stdin.write(target); Because the var spawn = require('child_process').spawn,
child = spawn('bad_command');
child.stderr.setEncoding('utf8');
child.stderr.on('data', function (data) {
if (/^execvp\(\)/.test(data)) {
console.log('Failed to start child process.');
}
}); Fixing this will likely require changing the API signature of the |
Actually, the module is designed to do that. Generally, this module is used for building apps which highlight stuff. So, if |
I must be missing something: How does one catch the error so the program doesn't crash? Try/catch around the |
Can you show me code? I want to see what exactly you are trying to do. |
var highlight = require("pygments").colorize;
try {
highlight('puts "Hello World"', 'ruby', 'console', console.log);
}
catch (error) {
console.error("Error thrown by pygments");
} Here is the error that is thrown if
|
Yes, this was intentional. I didn't want users to catch the error. Though, It could have a better error message. |
I can't understand why you would want the program to crash. Why not allow developers to catch the error and prevent hard crashes? |
I looked at the other issues you referenced above. I understand what you are trying to do and will support returning error. Are you interesting in doing the pull request? |
Sure, however the problem is that this will change the method signature for the If you're OK with changing the signature, then I can do the pull request. |
Yeah, I will just tag it as version v1.0.0 |
Any update on this? |
Hi, I am trying to run this module and getting error
Can you please help me here. |
You need to have the pygments tool installed along with this library. |
The library throws if
pygments
isn't installed on the system, with no way to catch the error.The text was updated successfully, but these errors were encountered: