aboutsummaryrefslogtreecommitdiff
path: root/bin/uglifyjs
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-02-27 03:40:54 +0800
committerGitHub <noreply@github.com>2017-02-27 03:40:54 +0800
commit872270b14986b2f24df406425eda5a3bf7a3b56a (patch)
tree5acd0f153bd43f1199b2f280a86d0a95c314f2e2 /bin/uglifyjs
parentb1c593a0419bf5ef0c6849262cb23bb34c97ea80 (diff)
downloadtracifyjs-872270b14986b2f24df406425eda5a3bf7a3b56a.tar.gz
tracifyjs-872270b14986b2f24df406425eda5a3bf7a3b56a.zip
improve error messages (#1506)
- better inheritance of `Error` sub-classes - mark parse error against source in CLI closes #235 closes #348 closes #524 closes #1356 closes #1405
Diffstat (limited to 'bin/uglifyjs')
-rwxr-xr-xbin/uglifyjs18
1 files changed, 16 insertions, 2 deletions
diff --git a/bin/uglifyjs b/bin/uglifyjs
index d0c3abb2..367d66e2 100755
--- a/bin/uglifyjs
+++ b/bin/uglifyjs
@@ -364,7 +364,21 @@ async.eachLimit(files, 1, function (file, cb) {
} catch(ex) {
if (ex instanceof UglifyJS.JS_Parse_Error) {
print_error("Parse error at " + file + ":" + ex.line + "," + ex.col);
- print_error(ex.message);
+ var col = ex.col;
+ var line = code.split(/\r?\n/)[ex.line - (col ? 1 : 2)];
+ if (line) {
+ if (col > 40) {
+ line = line.slice(col - 40);
+ col = 40;
+ }
+ if (col) {
+ print_error(line.slice(0, 80));
+ print_error(line.slice(0, col).replace(/\S/g, " ") + "^");
+ } else {
+ print_error(line.slice(-40));
+ print_error(line.slice(-40).replace(/\S/g, " ") + "^");
+ }
+ }
print_error(ex.stack);
process.exit(1);
}
@@ -390,7 +404,7 @@ async.eachLimit(files, 1, function (file, cb) {
var compressor = COMPRESS && UglifyJS.Compressor(COMPRESS);
} catch(ex) {
if (ex instanceof UglifyJS.DefaultsError) {
- print_error(ex.msg);
+ print_error(ex.message);
print_error("Supported options:");
print_error(sys.inspect(ex.defs));
process.exit(1);