Skip to content

Commit

Permalink
cli: fix crash on socket errors
Browse files Browse the repository at this point in the history
PR-URL: metarhia/jstp#174
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
  • Loading branch information
belochub committed May 24, 2017
1 parent 8be8b18 commit f175979
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tools/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const log = (msg) => {
if (userInput) rl.write(userInput);
};

const logErr = (err) => {
log(`${err.name} occurred: ${err.message}`);
};

function complete(input, completions) {
if (!input) return completions;
return completions.filter(c => c.startsWith(input));
Expand Down Expand Up @@ -89,7 +93,7 @@ rl.on('line', (line) => {
log(`Unknown command '${cmd}'`);
} else {
processor(leftover, (err, result) => {
if (err) return log(`${err.name} occurred: ${err.message}`);
if (err) return logErr(err);
log(result);
});
}
Expand Down Expand Up @@ -203,6 +207,7 @@ commandProcessor.connect = (
` in interface '${event.interfaceName}':` +
` ${jstp.stringify(event.remoteEventArgs)}`);
});
connection.on('error', err => logErr(err));
callback();
}
);
Expand Down

0 comments on commit f175979

Please sign in to comment.