Skip to content

Commit

Permalink
Helpful config file error message
Browse files Browse the repository at this point in the history
Fixes #728
  • Loading branch information
bitwiseman committed Jan 27, 2016
1 parent f81be85 commit ef68e97
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
26 changes: 18 additions & 8 deletions js/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,24 @@ var interpret = exports.interpret = function(argv, slice) {
process.exit(0);
}

var cfg = cc(
parsed,
cleanOptions(cc.env('jsbeautify_'), knownOpts),
parsed.config,
findRecursive(process.cwd(), '.jsbeautifyrc'),
verifyExists(path.join(getUserHome() || "", ".jsbeautifyrc")),
__dirname + '/../config/defaults.json'
).snapshot;
var cfg;
try {
cfg = cc(
parsed,
cleanOptions(cc.env('jsbeautify_'), knownOpts),
parsed.config,
findRecursive(process.cwd(), '.jsbeautifyrc'),
verifyExists(path.join(getUserHome() || "", ".jsbeautifyrc")),
__dirname + '/../config/defaults.json'
).snapshot;
} catch (ex) {
debug(cfg);
// usage(ex);
console.error(ex);
console.error('Error while loading beautifier configuration file.');
console.error('Run `' + getScriptName() + ' -h` for help.');
process.exit(1);
}

try {
// Verify arguments
Expand Down
6 changes: 6 additions & 0 deletions js/test/resources/configerror/.jsbeautifyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"indent_size": 11,
"indent_char": " "
"indent_level": 0,
"indent_with_tabs": false
}
Empty file.
7 changes: 7 additions & 0 deletions js/test/shell-smoke-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,18 @@ test_cli_js_beautify()
cleanup 1
}

cd $SCRIPT_DIR/resources/configerror
$CLI_SCRIPT $TEST_TEMP/example1-default.js 2>&1 | grep -q "Error while loading beautifier configuration file\." || {
echo "js-beautify output for $TEST_TEMP/example1-default.js was expected to be configration load error message."
cleanup 1
}

cd $SCRIPT_DIR/resources/indent11chars
$CLI_SCRIPT $TEST_TEMP/example1-default.js | diff -q $TEST_TEMP/example1-default.js - && {
echo "js-beautify output for $TEST_TEMP/example1-default.js was expected to be different based on CWD settings."
cleanup 1
}

cd $SCRIPT_DIR/resources/indent11chars/subDir1/subDir2
$CLI_SCRIPT $TEST_TEMP/example1-default.js | diff -q $TEST_TEMP/example1-default.js - && {
echo "js-beautify output for $TEST_TEMP/example1-default.js was expected to be different based on CWD parent folder settings."
Expand Down

0 comments on commit ef68e97

Please sign in to comment.