amoilanen / Brackets-Command-Line-Shortcuts

Brackets IDE plugin. Adds support of shortcuts for execution of terminal commands right from the IDE.
8 stars 1 forks source link

Shortcuts don't work after once a command failed #2

Open vuhrmeister opened 10 years ago

vuhrmeister commented 10 years ago

As soon as a command failed no following command will work at all. E.g. your second shotcut in example config (listing JS files) fails for me:

RUNNING 'find . […]'
ERROR: execvp(): No such file or directory

So after this error no shortcut works until I restart Brackets.

amoilanen commented 10 years ago

Here you encountered two problems, both are Linux-specific, on my Windows machine everything works fine.

I fixed the problem in the revision db2bea2f850976cf1bb142a946843e5b388c3759, also in the process I extracted the code that is responsible for running commands as a separate gist and tested it well separately https://gist.github.com/antivanov/20ee20b7a40995b1836c You can take a look.

Now it is possible to run commands with arguments in Linux.

However, when using the same code for running commands inside a Brackets extension some commands fail to run. In particular, from the example all the commands except for runCmdHandler("/home/anton/src/github/grunt-prepr", "grunt"); run successfully

This might be an issue with Brackets, need to further investigate. But in general simple commands should work. Things like git diff > ~/brackets.git.diff && gedit ~/brackets.git.diff & are not expected to work as of now (if for example, you want to see a quick git diff result).

For example, if you try to run a non-existing command the Node server will fatally fail somewhere at the low level. We have the following error handling code:

try {
    process = spawnProcess(dir, cmd);
  } catch (e) {
    console.error("Error trying to execute command '" + cmd + "' in directory '" + dir + "'");
    console.error(e);
    emit("error", e.message);
    emit("finished");
    return;
  }
process.stderr.on('data', function (data) {
    emit("error", data.toString('utf-8'));
  });

Error happens already somewhere after spawning a new process and we do not have enough control over error handling of that asynchronous code to prevent the Node server from crashing.

In Windows this is not a problem, all the errors are properly handled and the Node server does not crash. This looks like a Brackets bug.

amoilanen commented 9 years ago

From the developer guide this seems to be a known issue on the Brackets side https://github.com/adobe/brackets/wiki/Brackets-Node-Process:-Overview-for-Developers

Implement "safe mode" in Node core -- It is easy to write a domain that continually crashes Node. Right now, if we get two crashes within 5 seconds, we do not restart the Node process. The risk here is that the user will install an extension that repeatedly crashes Node, parts of Brackets will become unusable. For the things we have implemented now, this isn't a huge problem. But, if we start using Node for filesystem access, that means we could get into a state where the user's Node process crashes and he or she can't save their open documents.

And in fact if the Node process crashes the first time in Linux it does not get restarted. I will investigate this and maybe file an issue for Brackets