简体   繁体   中英

After successful execution of vorpal command error is thrown

I have add the following vorpal command.

vorpal
    .command('connect [username] [password]')
    .description('Connect to server.')
    .action(function (args, callback) {
        setTimeout(function () {
            // deleting options key from args
            delete args.options;

        var context = domain.create();

        // error handling in domain
        context.on('error', errorHandler);

        // running the connect in domain
        context.run(function() {
            console.log("Arguments : ", args);
        });
    }, 0);
});

vorpal.delimiter('hdb$').show();

Following is the stack trace as it is generated in side the vorpal library only.

Vorpal Prompt error: TypeError: Cannot read property 'setRawMode' of null
at ReadStream.setRawMode (tty.js:67:15)
at Interface._setRawMode (readline.js:177:23)
at new Interface (readline.js:137:10)
at Object.exports.createInterface (readline.js:39:10)
at Object.Interface.createInterface (/home/users/my-cli/node_modules/vorpal/node_modules/inquirer/node_modules/readline2/index.js:34:21)
at module.exports (/home/users/my-cli/node_modules/vorpal/node_modules/inquirer/lib/ui/baseUI.js:14:30)
at new module.exports (/home/users/my-cli/node_modules/vorpal/node_modules/inquirer/lib/ui/prompt.js:15:8)
at Object.promptModule as prompt
at Object.ui.prompt (/home/users/my-cli/node_modules/vorpal/lib/ui.js:171:25)
at EventEmitter.vorpal._prompt (/home/users/my-cli/node_modules/vorpal/lib/vorpal.js:528:15)
at EventEmitter. (/home/users/my-cli/node_modules/vorpal/lib/vorpal.js:542:12)
at callback (/home/users/my-cli/node_modules/vorpal/lib/vorpal.js:705:22)
at /home/users/my-cli/node_modules/vorpal/lib/vorpal.js:824:7
at EventEmitter._commandSetCallback (/home/users/my-cli/node_modules/vorpal/lib/session.js:455:5)
at EventEmitter.session.completeCommand (/home/users/my-cli/node_modules/vorpal/lib/session.js:519:12)
at onCompletion (/home/users/my-cli/node_modules/vorpal/lib/session.js:465:10)

Please let me know if I am doing something wrong in this.

I think this may simply be because you aren't running the callback after the command completes:

var vorpal = require('vorpal')();

vorpal
    .command('connect [username] [password]')
    .description('Connect to server.')
    .action(function (args, callback) {
      setTimeout(function(){
        // ... your logic
        callback();
      }, 0)
    });

vorpal.delimiter('hdb$').show();

The above works - start with the above logic, and then start adding in your logic. If it breaks again even with the callback, back track on a process of elimination to find what part of your logic is causing the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM