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

cli: refine error messages #135

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions tools/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ rl.on('line', (line) => {
if (!processor) {
log(`Unknown command '${cmd}'`);
} else {
processor(leftover, (err, result) => {
processor(leftover.trim(), (err, result) => {
if (err) return log(`${err.name} occurred: ${err.message}`);
log(result);
});
Expand Down 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 @@ -238,14 +247,17 @@ lineProcessor.event = (tokens, callback) => {
};

lineProcessor.connect = (tokens, callback) => {
if (tokens === undefined) {
return callback(new Error('Not enough arguments'));
if (tokens === undefined || tokens.startsWith(':')) {
return callback(reportMissingArgument('Host'));
}
const args = _split(tokens, ' ', 2);
const [host, port] = _split(args[0], ':');
if (port === undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here host can be undefined as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@belochub done

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