Skip to content

Commit

Permalink
cli: refine error messages
Browse files Browse the repository at this point in the history
* make all missing argument errors conform to single style
* report error on missing host/port, {method,event} name
  • Loading branch information
lundibundi committed May 6, 2017
1 parent 8a6bc52 commit a06f8c6
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions tools/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,17 @@ function _split(str, separator, limit, leaveEmpty) {
return result;
}

const reportMissingArgument =
missing => new Error(`${missing} is not provided`);

lineProcessor.call = (tokens, callback) => {
if (tokens === undefined) {
return callback(new Error('Not enough arguments'));
return callback(reportMissingArgument('Interface name'));
}
const args = _split(tokens, ' ', 2);
if (args.length === 1) {
return callback(reportMissingArgument('Method name'));
}
let methodArgs;
try {
methodArgs = jstp.parse('[' + args[2] + ']');
Expand All @@ -222,9 +228,12 @@ lineProcessor.call = (tokens, callback) => {

lineProcessor.event = (tokens, callback) => {
if (tokens === undefined) {
return callback(new Error('Not enough arguments'));
return callback(reportMissingArgument('Interface name'));
}
const args = _split(tokens, ' ', 2);
if (args.length === 1) {
return callback(reportMissingArgument('Event name'));
}
let eventArgs;
try {
eventArgs = jstp.parse('[' + args[2] + ']');
Expand All @@ -239,13 +248,16 @@ lineProcessor.event = (tokens, callback) => {

lineProcessor.connect = (tokens, callback) => {
if (tokens === undefined) {
return callback(new Error('Not enough arguments'));
return callback(reportMissingArgument('Host'));
}
const args = _split(tokens, ' ', 2);
const [host, port] = _split(args[0], ':');
if (port === undefined) {
return callback(reportMissingArgument('Port'));
}
const appName = args[1];
if (appName === undefined) {
return callback(new Error('Application name is not provided'));
return callback(reportMissingArgument('Application name'));
}
commandProcessor.connect(host, port, appName, (err) => {
if (err) return callback(err);
Expand Down

0 comments on commit a06f8c6

Please sign in to comment.