| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e5e60f5 commit d4b41f6
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -567,11 +567,28 @@ function REPLServer(prompt, | |||
| 567 | 567 | }); | |
| 568 | 568 | } else { | |
| 569 | 569 | if (errStack === '') { | |
| 570 | - errStack = `Thrown: ${self.writer(e)}\n`; | ||
| 571 | - } else { | ||
| 572 | - const ln = errStack.endsWith('\n') ? '' : '\n'; | ||
| 573 | - errStack = `Thrown:\n${errStack}${ln}`; | ||
| 570 | + errStack = self.writer(e); | ||
| 571 | + } | ||
| 572 | + const lines = errStack.split(/(?<=\n)/); | ||
| 573 | + let matched = false; | ||
| 574 | + | ||
| 575 | + errStack = ''; | ||
| 576 | + for (const line of lines) { | ||
| 577 | + if (!matched && /^\[?([A-Z][a-z0-9_]*)*Error/.test(line)) { | ||
| 578 | + errStack += writer.options.breakLength >= line.length ? | ||
| 579 | + `Uncaught ${line}` : | ||
| 580 | + `Uncaught:\n${line}`; | ||
| 581 | + matched = true; | ||
| 582 | + } else { | ||
| 583 | + errStack += line; | ||
| 584 | + } | ||
| 585 | + } | ||
| 586 | + if (!matched) { | ||
| 587 | + const ln = lines.length === 1 ? ' ' : ':\n'; | ||
| 588 | + errStack = `Uncaught${ln}${errStack}`; | ||
| 574 | 589 | } | |
| 590 | + // Normalize line endings. | ||
| 591 | + errStack += errStack.endsWith('\n') ? '' : '\n'; | ||
| 575 | 592 | top.outputStream.write(errStack); | |
| 576 | 593 | top.clearBufferedCommand(); | |
| 577 | 594 | top.lines.level = []; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,7 +30,7 @@ const child = spawn(process.execPath, args); | |||
| 30 | 30 | const input = '(function(){"use strict"; const y=1;y=2})()\n'; | |
| 31 | 31 | // This message will vary based on JavaScript engine, so don't check the message | |
| 32 | 32 | // contents beyond confirming that the `Error` is a `TypeError`. | |
| 33 | - const expectOut = /> Thrown:\nTypeError: /; | ||
| 33 | + const expectOut = /> Uncaught TypeError: /; | ||
| 34 | 34 | ||
| 35 | 35 | child.stderr.setEncoding('utf8'); | |
| 36 | 36 | child.stderr.on('data', (d) => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,5 +20,5 @@ replserver.emit('line', '.exit'); | |||
| 20 | 20 | ||
| 21 | 21 | setTimeout(() => { | |
| 22 | 22 | console.log(text); | |
| 23 | - assert(text.includes('Thrown: null')); | ||
| 23 | + assert(text.includes('Uncaught null')); | ||
| 24 | 24 | }, 0); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,26 +48,26 @@ const tests = [ | |||
| 48 | 48 | { | |
| 49 | 49 | // test .load for a file that throws | |
| 50 | 50 | command: `.load ${fixtures.path('repl-pretty-stack.js')}`, | |
| 51 | - expected: 'Thrown:\nError: Whoops!--->\nrepl:*:*--->\nd (repl:*:*)' + | ||
| 51 | + expected: 'Uncaught Error: Whoops!--->\nrepl:*:*--->\nd (repl:*:*)' + | ||
| 52 | 52 | '--->\nc (repl:*:*)--->\nb (repl:*:*)--->\na (repl:*:*)\n' | |
| 53 | 53 | }, | |
| 54 | 54 | { | |
| 55 | 55 | command: 'let x y;', | |
| 56 | - expected: 'Thrown:\n' + | ||
| 57 | - 'let x y;\n ^\n\nSyntaxError: Unexpected identifier\n' | ||
| 56 | + expected: 'let x y;\n ^\n\n' + | ||
| 57 | + 'Uncaught SyntaxError: Unexpected identifier\n' | ||
| 58 | 58 | }, | |
| 59 | 59 | { | |
| 60 | 60 | command: 'throw new Error(\'Whoops!\')', | |
| 61 | - expected: 'Thrown:\nError: Whoops!\n' | ||
| 61 | + expected: 'Uncaught Error: Whoops!\n' | ||
| 62 | 62 | }, | |
| 63 | 63 | { | |
| 64 | 64 | command: 'foo = bar;', | |
| 65 | - expected: 'Thrown:\nReferenceError: bar is not defined\n' | ||
| 65 | + expected: 'Uncaught ReferenceError: bar is not defined\n' | ||
| 66 | 66 | }, | |
| 67 | 67 | // test anonymous IIFE | |
| 68 | 68 | { | |
| 69 | 69 | command: '(function() { throw new Error(\'Whoops!\'); })()', | |
| 70 | - expected: 'Thrown:\nError: Whoops!--->\nrepl:*:*\n' | ||
| 70 | + expected: 'Uncaught Error: Whoops!--->\nrepl:*:*\n' | ||
| 71 | 71 | } | |
| 72 | 72 | ]; | |
| 73 | 73 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,7 @@ const repl = require('repl'); | |||
| 7 | 7 | ||
| 8 | 8 | const stackRegExp = /(at .*repl:)[0-9]+:[0-9]+/g; | |
| 9 | 9 | ||
| 10 | - function run({ command, expected, ...extraREPLOptions }) { | ||
| 10 | + function run({ command, expected, ...extraREPLOptions }, i) { | ||
| 11 | 11 | let accum = ''; | |
| 12 | 12 | ||
| 13 | 13 | const inputStream = new ArrayStream(); | |
@@ -25,6 +25,7 @@ function run({ command, expected, ...extraREPLOptions }) { | |||
| 25 | 25 | }); | |
| 26 | 26 | ||
| 27 | 27 | r.write(`${command}\n`); | |
| 28 | + console.log(i); | ||
| 28 | 29 | assert.strictEqual( | |
| 29 | 30 | accum.replace(stackRegExp, '$1*:*'), | |
| 30 | 31 | expected.replace(stackRegExp, '$1*:*') | |
@@ -36,39 +37,39 @@ const tests = [ | |||
| 36 | 37 | { | |
| 37 | 38 | // Test .load for a file that throws. | |
| 38 | 39 | command: `.load ${fixtures.path('repl-pretty-stack.js')}`, | |
| 39 | - expected: 'Thrown:\nError: Whoops!\n at repl:*:*\n' + | ||
| 40 | + expected: 'Uncaught Error: Whoops!\n at repl:*:*\n' + | ||
| 40 | 41 | ' at d (repl:*:*)\n at c (repl:*:*)\n' + | |
| 41 | 42 | ' at b (repl:*:*)\n at a (repl:*:*)\n' | |
| 42 | 43 | }, | |
| 43 | 44 | { | |
| 44 | 45 | command: 'let x y;', | |
| 45 | - expected: 'Thrown:\n' + | ||
| 46 | - 'let x y;\n ^\n\nSyntaxError: Unexpected identifier\n' | ||
| 46 | + expected: 'let x y;\n ^\n\n' + | ||
| 47 | + 'Uncaught SyntaxError: Unexpected identifier\n' | ||
| 47 | 48 | }, | |
| 48 | 49 | { | |
| 49 | 50 | command: 'throw new Error(\'Whoops!\')', | |
| 50 | - expected: 'Thrown:\nError: Whoops!\n' | ||
| 51 | + expected: 'Uncaught Error: Whoops!\n' | ||
| 51 | 52 | }, | |
| 52 | 53 | { | |
| 53 | 54 | command: '(() => { const err = Error(\'Whoops!\'); ' + | |
| 54 | 55 | 'err.foo = \'bar\'; throw err; })()', | |
| 55 | - expected: "Thrown:\nError: Whoops!\n at repl:*:* {\n foo: 'bar'\n}\n", | ||
| 56 | + expected: "Uncaught Error: Whoops!\n at repl:*:* {\n foo: 'bar'\n}\n", | ||
| 56 | 57 | }, | |
| 57 | 58 | { | |
| 58 | 59 | command: '(() => { const err = Error(\'Whoops!\'); ' + | |
| 59 | 60 | 'err.foo = \'bar\'; throw err; })()', | |
| 60 | - expected: 'Thrown:\nError: Whoops!\n at repl:*:* {\n foo: ' + | ||
| 61 | + expected: 'Uncaught Error: Whoops!\n at repl:*:* {\n foo: ' + | ||
| 61 | 62 | "\u001b[32m'bar'\u001b[39m\n}\n", | |
| 62 | 63 | useColors: true | |
| 63 | 64 | }, | |
| 64 | 65 | { | |
| 65 | 66 | command: 'foo = bar;', | |
| 66 | - expected: 'Thrown:\nReferenceError: bar is not defined\n' | ||
| 67 | + expected: 'Uncaught ReferenceError: bar is not defined\n' | ||
| 67 | 68 | }, | |
| 68 | 69 | // Test anonymous IIFE. | |
| 69 | 70 | { | |
| 70 | 71 | command: '(function() { throw new Error(\'Whoops!\'); })()', | |
| 71 | - expected: 'Thrown:\nError: Whoops!\n at repl:*:*\n' | ||
| 72 | + expected: 'Uncaught Error: Whoops!\n at repl:*:*\n' | ||
| 72 | 73 | } | |
| 73 | 74 | ]; | |
| 74 | 75 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -118,15 +118,15 @@ async function ordinaryTests() { | |||
| 118 | 118 | [ 'if (await true) { function bar() {}; }', 'undefined' ], | |
| 119 | 119 | [ 'bar', '[Function: bar]' ], | |
| 120 | 120 | [ 'if (await true) { class Bar {}; }', 'undefined' ], | |
| 121 | - [ 'Bar', 'ReferenceError: Bar is not defined', { line: 1 } ], | ||
| 121 | + [ 'Bar', 'Uncaught ReferenceError: Bar is not defined' ], | ||
| 122 | 122 | [ 'await 0; function* gen(){}', 'undefined' ], | |
| 123 | 123 | [ 'for (var i = 0; i < 10; ++i) { await i; }', 'undefined' ], | |
| 124 | 124 | [ 'i', '10' ], | |
| 125 | 125 | [ 'for (let j = 0; j < 5; ++j) { await j; }', 'undefined' ], | |
| 126 | - [ 'j', 'ReferenceError: j is not defined', { line: 1 } ], | ||
| 126 | + [ 'j', 'Uncaught ReferenceError: j is not defined' ], | ||
| 127 | 127 | [ 'gen', '[GeneratorFunction: gen]' ], | |
| 128 | - [ 'return 42; await 5;', 'SyntaxError: Illegal return statement', | ||
| 129 | - { line: 4 } ], | ||
| 128 | + [ 'return 42; await 5;', 'Uncaught SyntaxError: Illegal return statement', | ||
| 129 | + { line: 3 } ], | ||
| 130 | 130 | [ 'let o = await 1, p', 'undefined' ], | |
| 131 | 131 | [ 'p', 'undefined' ], | |
| 132 | 132 | [ 'let q = 1, s = await 2', 'undefined' ], | |
@@ -160,7 +160,7 @@ async function ctrlCTest() { | |||
| 160 | 160 | { ctrl: true, name: 'c' } | |
| 161 | 161 | ]), [ | |
| 162 | 162 | 'await timeout(100000)\r', | |
| 163 | - 'Thrown:', | ||
| 163 | + 'Uncaught:', | ||
| 164 | 164 | '[Error [ERR_SCRIPT_EXECUTION_INTERRUPTED]: ' + | |
| 165 | 165 | 'Script execution was interrupted by `SIGINT`] {', | |
| 166 | 166 | " code: 'ERR_SCRIPT_EXECUTION_INTERRUPTED'", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,8 +18,7 @@ child.on('exit', common.mustCall(() => { | |||
| 18 | 18 | [ | |
| 19 | 19 | 'Type ".help" for more information.', | |
| 20 | 20 | // x\n | |
| 21 | - '> Thrown:', | ||
| 22 | - 'ReferenceError: x is not defined', | ||
| 21 | + '> Uncaught ReferenceError: x is not defined', | ||
| 23 | 22 | // Added `uncaughtException` listener. | |
| 24 | 23 | '> short', | |
| 25 | 24 | 'undefined', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,7 @@ const repl = require('repl'); | |||
| 6 | 6 | ||
| 7 | 7 | let count = 0; | |
| 8 | 8 | ||
| 9 | - function run({ command, expected }) { | ||
| 9 | + function run({ command, expected, useColors = false }) { | ||
| 10 | 10 | let accum = ''; | |
| 11 | 11 | ||
| 12 | 12 | const output = new ArrayStream(); | |
@@ -17,7 +17,7 @@ function run({ command, expected }) { | |||
| 17 | 17 | input: new ArrayStream(), | |
| 18 | 18 | output, | |
| 19 | 19 | terminal: false, | |
| 20 | - useColors: false | ||
| 20 | + useColors | ||
| 21 | 21 | }); | |
| 22 | 22 | ||
| 23 | 23 | r.write(`${command}\n`); | |
@@ -30,35 +30,40 @@ function run({ command, expected }) { | |||
| 30 | 30 | // Verify that the repl is still working as expected. | |
| 31 | 31 | accum = ''; | |
| 32 | 32 | r.write('1 + 1\n'); | |
| 33 | - assert.strictEqual(accum, '2\n'); | ||
| 33 | + // eslint-disable-next-line no-control-regex | ||
| 34 | + assert.strictEqual(accum.replace(/\u001b\[[0-9]+m/g, ''), '2\n'); | ||
| 34 | 35 | r.close(); | |
| 35 | 36 | count++; | |
| 36 | 37 | } | |
| 37 | 38 | ||
| 38 | 39 | const tests = [ | |
| 39 | 40 | { | |
| 41 | + useColors: true, | ||
| 40 | 42 | command: 'x', | |
| 41 | - expected: 'Thrown:\n' + | ||
| 42 | - 'ReferenceError: x is not defined\n' | ||
| 43 | + expected: 'Uncaught ReferenceError: x is not defined\n' | ||
| 44 | + }, | ||
| 45 | + { | ||
| 46 | + useColors: true, | ||
| 47 | + command: 'throw { foo: "test" }', | ||
| 48 | + expected: "Uncaught { foo: \x1B[32m'test'\x1B[39m }\n" | ||
| 43 | 49 | }, | |
| 44 | 50 | { | |
| 45 | 51 | command: 'process.on("uncaughtException", () => console.log("Foobar"));\n', | |
| 46 | - expected: /^Thrown:\nTypeError \[ERR_INVALID_REPL_INPUT]: Listeners for `/ | ||
| 52 | + expected: /^Uncaught:\nTypeError \[ERR_INVALID_REPL_INPUT]: Listeners for `/ | ||
| 47 | 53 | }, | |
| 48 | 54 | { | |
| 49 | 55 | command: 'x;\n', | |
| 50 | - expected: 'Thrown:\n' + | ||
| 51 | - 'ReferenceError: x is not defined\n' | ||
| 56 | + expected: 'Uncaught ReferenceError: x is not defined\n' | ||
| 52 | 57 | }, | |
| 53 | 58 | { | |
| 54 | 59 | command: 'process.on("uncaughtException", () => console.log("Foobar"));' + | |
| 55 | 60 | 'console.log("Baz");\n', | |
| 56 | - expected: /^Thrown:\nTypeError \[ERR_INVALID_REPL_INPUT]: Listeners for `/ | ||
| 61 | + expected: /^Uncaught:\nTypeError \[ERR_INVALID_REPL_INPUT]: Listeners for `/ | ||
| 57 | 62 | }, | |
| 58 | 63 | { | |
| 59 | 64 | command: 'console.log("Baz");' + | |
| 60 | 65 | 'process.on("uncaughtException", () => console.log("Foobar"));\n', | |
| 61 | - expected: /^Baz\nThrown:\nTypeError \[ERR_INVALID_REPL_INPUT]:.*uncaughtException/ | ||
| 66 | + expected: /^Baz\nUncaught:\nTypeError \[ERR_INVALID_REPL_INPUT]:.*uncaughtException/ | ||
| 62 | 67 | } | |
| 63 | 68 | ]; | |
| 64 | 69 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -173,13 +173,11 @@ function testError() { | |||
| 173 | 173 | 'undefined', | |
| 174 | 174 | ||
| 175 | 175 | // The error, both from the original throw and the `_error` echo. | |
| 176 | - 'Thrown:', | ||
| 177 | - 'Error: foo', | ||
| 176 | + 'Uncaught Error: foo', | ||
| 178 | 177 | '[Error: foo]', | |
| 179 | 178 | ||
| 180 | 179 | // The sync error, with individual property echoes | |
| 181 | - 'Thrown:', | ||
| 182 | - /^Error: ENOENT: no such file or directory, scandir '.*nonexistent\?'/, | ||
| 180 | + /^Uncaught Error: ENOENT: no such file or directory, scandir '.*nonexistent\?'/, | ||
| 183 | 181 | /Object\.readdirSync/, | |
| 184 | 182 | /^ errno: -(2|4058),$/, | |
| 185 | 183 | " syscall: 'scandir',", | |
@@ -194,8 +192,7 @@ function testError() { | |||
| 194 | 192 | 'undefined', | |
| 195 | 193 | ||
| 196 | 194 | // The message from the original throw | |
| 197 | - 'Thrown:', | ||
| 198 | - 'Error: baz', | ||
| 195 | + 'Uncaught Error: baz', | ||
| 199 | 196 | ]; | |
| 200 | 197 | for (const line of lines) { | |
| 201 | 198 | const expected = expectedLines.shift(); | |
@@ -218,8 +215,7 @@ function testError() { | |||
| 218 | 215 | "'baz'", | |
| 219 | 216 | 'Expression assignment to _error now disabled.', | |
| 220 | 217 | '0', | |
| 221 | - 'Thrown:', | ||
| 222 | - 'Error: quux', | ||
| 218 | + 'Uncaught Error: quux', | ||
| 223 | 219 | '0' | |
| 224 | 220 | ]); | |
| 225 | 221 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments