Skip to content
This repository has been archived by the owner on Apr 27, 2021. It is now read-only.

Commit

Permalink
Handles errors a little better.
Browse files Browse the repository at this point in the history
  • Loading branch information
paullewis committed Feb 10, 2016
1 parent b7e5002 commit 2c74a04
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions bigrig.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,16 @@ if (path === '' && typeof argv._ !== 'undefined' && argv._.length > 0) {

// Check the file exists.
try {

fs.statSync(path);
traceContents = fs.readFileSync(path, 'utf8');
processContents(traceContents);

} catch (e) {
} catch (fileProcessError) {

if (typeof e === 'string') {
console.warn(clc.red('Unable to process trace: ') + clc.yellow(e));
process.exit(1);
if (typeof fileProcessError === 'string' ||
fileProcessError.code !== 'ENOENT') {
bailWithMessage(fileProcessError.toString());
}

var checkedFirstChunk = false;
Expand Down Expand Up @@ -90,12 +91,14 @@ try {
});

process.stdin.on('end', function () {
processContents(traceContents, {
strict: argv.strict
});
try {
processContents(traceContents, {
strict: argv.strict
});
} catch (processError) {
bailWithMessage(processError.toString());
}
});

throw e;
}

function processContents (contents) {
Expand All @@ -113,6 +116,11 @@ function processContents (contents) {

}

function bailWithMessage (msg) {
console.warn(clc.red('Unable to process trace: ') + clc.yellow(msg));
process.exit(1);
}

function prettyPrint (result, indent, frameCount) {

indent = indent || 0;
Expand Down

0 comments on commit 2c74a04

Please sign in to comment.