Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

fix for the handling of bad input in "mojito jsling mojit" command #542

Merged
merged 2 commits into from

4 participants

Dmitry Savintsev Isao Yagi Fabian Frank lzhan
Dmitry Savintsev

Currently running the command:
mojito jslint mojit
produces a not so user-friendly Javascript error:

$ mojito jslint mojit
path.existsSync is now called fs.existsSync.

/Users/dmitris/.nvm/v0.8.9/lib/node_modules/mojito/lib/app/commands/jslint.js:312
var parts = mojitPath.split('/');
^
TypeError: Cannot call method 'split' of undefined
at getMojitName (/Users/dmitris/.nvm/v0.8.9/lib/node_modules/mojito/lib/app/commands/jslint.js:312:27)
at Object.run (/Users/dmitris/.nvm/v0.8.9/lib/node_modules/mojito/lib/app/commands/jslint.js:451:13)
at main (/Users/dmitris/.nvm/v0.8.9/lib/node_modules/mojito/lib/management/cli.js:125:13)
at Object. (/Users/dmitris/.nvm/v0.8.9/lib/node_modules/mojito/lib/management/cli.js:137:1)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
at require (module.js:378:17)

the same if you mistype the path to the mojit:

I fixed the handling of the missing and incorrect input and modified the usage/help message to be:

mojito jslint [app | mojit] [] {options}
- target: app or mojit
- path (required for a mojit target): the path to the mojit to run jslint on

Run jslint on the app in the current directory:
mojito jslint app .
Run jslint on mojits/Bar:
mojito jslint mojit ./mojits/Bar
Run jslint on the mojito framework itself!
mojito jslint

OPTIONS:
--print : print results to stdout
-p : short for --print

(which would also highlight the fact that "mojito jslint" runs checks on the Mojito framework itself, not the app in the current directory).

jslint output on lib/app/commands/jslint.js is clean. The tests seem to run fine ("mojito test").

I was not sure - am I supposed to write unit or other tests for the command-line handlers? Please let me know, if required I will add them. Thanks.

Dmitry Savin... added some commits
Dmitry Savintsev Fixed handling of bad input for mojito jslint mojit command, modified…
… the help/usage message
bfc2617
Dmitry Savintsev minor change of the wording for the error to reflect that we need the…
… path to the mojit like mojits/Bar not just its name
740af31
Dmitry Savintsev

Here's the current error if you mistype the mojito name (path):

$ mojito jslint mojit mojits/QueryMojito

fs.js:500
return binding.readdir(pathModule._makeLong(path));
^
Error: ENOENT, no such file or directory '/Users/dmitris/dev/hack/my-mojito/examples/developer-guide/using_parameters/mojits/QueryMojito'
at Object.fs.readdirSync (fs.js:500:18)
at processDir (/Users/dmitris/.nvm/v0.8.9/lib/node_modules/mojito/lib/app/commands/jslint.js:93:20)
at processFiles (/Users/dmitris/.nvm/v0.8.9/lib/node_modules/mojito/lib/app/commands/jslint.js:361:5)
at Object.run (/Users/dmitris/.nvm/v0.8.9/lib/node_modules/mojito/lib/app/commands/jslint.js:478:14)
at main (/Users/dmitris/.nvm/v0.8.9/lib/node_modules/mojito/lib/management/cli.js:125:13)
at Object. (/Users/dmitris/.nvm/v0.8.9/lib/node_modules/mojito/lib/management/cli.js:137:1)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)

I changed it to:

$ mojito jslint mojit mojits/QueryMojito
✖ Mojit mojits/QueryMojito not found.
usage:
mojito jslint [app | mojit] [] {options}
- target: app or mojit
- path (required for a mojit target): the path to the mojit to run jslint on

Run jslint on the app in the current directory:
mojito jslint app .
Run jslint on mojits/Bar:
mojito jslint mojit ./mojits/Bar
Run jslint on the mojito framework itself!
mojito jslint

OPTIONS:
--print : print results to stdout
-p : short for --print

Isao Yagi

+1

lzhan lzhan was assigned
lzhan lzhan merged commit 740af31 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 21, 2012
  1. Fixed handling of bad input for mojito jslint mojit command, modified…

    Dmitry Savintsev authored
    … the help/usage message
  2. minor change of the wording for the error to reflect that we need the…

    Dmitry Savintsev authored
    … path to the mojit like mojits/Bar not just its name
This page is out of date. Refresh to see the latest.
Showing with 22 additions and 4 deletions.
  1. +22 −4 lib/app/commands/jslint.js
26 lib/app/commands/jslint.js
View
@@ -12,7 +12,15 @@ var fs = require('fs'),
path = require('path'),
existsSync = fs.existsSync || path.existsSync,
utils = require(path.join(__dirname, '../../management/utils')),
- usage = 'mojito jslint [app | mojit] [<name>] {options}\n' +
+ usage = 'mojito jslint [app | mojit] [<path>] {options}\n' +
+ '\t- target: app or mojit\n' +
+ '\t- path (required for a mojit target): the path to the mojit to run jslint on\n\n' +
+ 'Run jslint on the app in the current directory:\n' +
+ '\tmojito jslint app .\n' +
+ 'Run jslint on mojits/Bar:\n' +
+ '\tmojito jslint mojit ./mojits/Bar\n' +
+ 'Run jslint on the mojito framework itself!\n' +
+ '\tmojito jslint\n' +
'\nOPTIONS: \n' +
'\t --print : print results to stdout \n' +
'\t -p : short for --print\n',
@@ -409,6 +417,7 @@ function run(params, options) {
outDir,
failures,
errors,
+ mojit_path,
print = options && options.print;
// Process params to determine input and output locations.
@@ -442,13 +451,22 @@ function run(params, options) {
];
} else if (params[0] === 'mojit') {
// mojit
- inDir = getMojitDir(params[1]);
+ mojit_path = params[1];
+ if (!mojit_path) {
+ utils.error('Please specify the path to mojit', exports.usage);
+ return;
+ }
+ inDir = getMojitDir(mojit_path);
+ if (!existsSync(inDir)) {
+ utils.error('Mojit ' + mojit_path + ' not found.', usage);
+ return;
+ }
if (!inDir) {
- utils.error('Mojit not found.', usage);
+ utils.error('Mojit ' + mojit_path + ' not found.', usage);
return;
}
outDir = path.join(inDir, 'artifacts/jslint/mojits',
- getMojitName(params[1]));
+ getMojitName(mojit_path));
excludes = [
/\/tests$/,
/\/artifacts$/,
Something went wrong with that request. Please try again.