Skip to content

Commit

Permalink
gracefully handle non-Error being thrown (#1893)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed May 9, 2017
1 parent 41996be commit a0f5f86
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions bin/uglifyjs
Expand Up @@ -193,7 +193,7 @@ function run() {
}
}
} catch (ex) {
fatal(ex.stack);
fatal(ex);
}
var result = UglifyJS.minify(files, options);
if (result.error) {
Expand All @@ -220,7 +220,7 @@ function run() {
console.error("Supported options:");
console.error(ex.defs);
}
fatal(ex.stack);
fatal(ex);
} else if (program.output == "ast") {
console.log(JSON.stringify(result.ast, function(key, value) {
if (skip_key(key)) return;
Expand Down Expand Up @@ -263,7 +263,8 @@ function run() {
}

function fatal(message) {
console.error(message.replace(/^\S*?Error:/, "ERROR:"));
if (message instanceof Error) message = message.stack.replace(/^\S*?Error:/, "ERROR:")
console.error(message);
process.exit(1);
}

Expand Down Expand Up @@ -303,7 +304,7 @@ function read_file(path, default_value) {
return fs.readFileSync(path, "utf8");
} catch (ex) {
if (ex.code == "ENOENT" && default_value != null) return default_value;
fatal(ex.stack);
fatal(ex);
}
}

Expand Down

0 comments on commit a0f5f86

Please sign in to comment.