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

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

Open
gledis69 opened this issue Oct 11, 2020 · 1 comment

Comments

@gledis69
Copy link

_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
Copy link

Younanator commented Dec 17, 2020

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.

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