Skip to content

Commit

Permalink
Handle syntax errors in expression
Browse files Browse the repository at this point in the history
  • Loading branch information
danielstjules committed Aug 11, 2014
1 parent 10da929 commit 3a73e1e
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions bin/pjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,26 @@ function inputHandler(err, accumulator) {
process.exit(1);
}

// Apply filter, map and reduce, and output results
['filter', 'map', 'reduce'].forEach(function(action) {
if (program[action]) {
accumulator = pjs[action](accumulator, program[action], program.explicit);
var runActions = function() {
// Apply filter, map and reduce, and output results
['filter', 'map', 'reduce'].forEach(function(action) {
if (program[action]) {
accumulator = pjs[action](accumulator, program[action], program.explicit);
}
});
};

try {
runActions();
} catch (e) {
if (e instanceof SyntaxError || e instanceof ReferenceError) {
console.error('Invalid expression :', e.message);
} else {
console.error(e.stack);
}
});

process.exit(3);
}

if (accumulator instanceof Array && program.json) {
console.log(JSON.stringify(accumulator));
Expand Down

0 comments on commit 3a73e1e

Please sign in to comment.