microsoft / node-pty

Fork pseudoterminals in Node.JS
Other
1.47k stars 240 forks source link

Calling spawn with an invalid path causes .spawn to never return #138

Open Tyriar opened 7 years ago

Tyriar commented 7 years ago

VS Code issues:

Tyriar commented 7 years ago

Struggling to reproduce the hanging call in node-pty 😕. The following test ends up calling the same native API but throws a Node.js exception just fine:

  describe('WindowsTerminal', () => {
    describe('constructor', () => {
      describe('given an invalid launch path', () => {
        it('should fail gracefully', () => {
          // const term = new WindowsTerminal('');
          // const term = new WindowsTerminal('some_file_not_on_the_path');
          const term = new WindowsTerminal('C:\\WINDOWS\\System32', '', {
            name: "System32",
            cwd: "C:\\Users\\daimms.REDMOND\\Documents\\playground\\t",
          });
        });
      });
    });
  });
  23 passing (552ms)
  1 failing

  1) WindowsTerminal constructor given an invalid launch path should fail gracefully:
     Error: File not found: C:\WINDOWS\System32
      at new WindowsPtyAgent (lib\windowsPtyAgent.js:25:24)
      at new WindowsTerminal (lib\windowsTerminal.js:45:24)
      at Context.<anonymous> (lib\windowsTerminal.test.js:16:32)
Tyriar commented 7 years ago

One way to be sure about this is to use which https://github.com/Tyriar/node-pty/issues/112 and validate this on the JS side. One perk here is a lot of C++ code can be removed from path_utils.cc