rannn505 / child-shell

Node.js bindings 🔗 for shell
http://rannn505.github.io/child-shell/
MIT License
299 stars 71 forks source link

.catch() doesn't seem to catch .invoke() error when the ps process is destroyed #126

Open gledis69 opened 3 years ago

gledis69 commented 3 years ago
_safelyRunCommand: function(command, callback = undefined, error = undefined){

        this._ps.addCommand(command);

        this._ps.invoke()
            .catch((e) => {
                console.log("ps destroyed!!");
                this._ps.dispose();
                this._ps = new Shell({
                    executionPolicy: 'Bypass',
                    noProfile: true
                });

                this._safelyRunCommand(command, callback, error);
            });
    },

I manually destroy the powershell process created by new Shell(...) just to try and test some edge cases, and the .catch() block after .invoke() doesn't catch the issue and:

(node:6600) UnhandledPromiseRejectionWarning: Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed at doWrite (_stream_writable.js:411:19) at writeOrBuffer (_stream_writable.js:399:5) at Socket.Writable.write (_stream_writable.js:299:11) at resolve (C:\PATH\node_modules\node-powershell\lib\utils.js:44:14) at new Promise () at shellSafeWrite (C:\PATH\node_modules\node-powershell\lib\utils.js:43:41) at Shell.invoke (C:\PATH\node_modules\node-powershell\lib\Shell.js:188:5) at Object._safelyRunCommand (C:\PATH\DockerManager.js:14:18) at Object.startDocker (C:\PATH\DockerManager.js:32:14) at Timeout.setTimeout [as _onTimeout] (C:\PATH\main.js:5:31) (node:6600) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2) (node:6600) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Is returned.

Please let me know if I am missing smth here or is it is a bug in the node-powershell...

Younanator commented 3 years ago

Getting the same error on one of my machines but not on the other

Downgrading to version 3.3.1 from 4.0.0 fixed this issue for me.