Skip to content

Commit

Permalink
test: remove cjs loader from stack traces
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoffreyBooth committed Aug 10, 2022
1 parent ec44403 commit 3e255df
Show file tree
Hide file tree
Showing 57 changed files with 121 additions and 277 deletions.
27 changes: 27 additions & 0 deletions test/errors/throw-error-with-getter-throw-traced.mjs
@@ -0,0 +1,27 @@
import { spawnPromisified } from '../common/index.mjs';
import assert from 'node:assert';
import { execPath } from 'node:process';
import { describe, it } from 'node:test';


describe('--trace-uncaught', () => {
it('prints a trace on process exit for uncaught errors', async () => {
const { code, signal, stderr } = await spawnPromisified(execPath, [
'--trace-uncaught',
'--eval',
`throw {
get stack() {
throw new Error('weird throw but ok');
},
get name() {
throw new Error('weird throw but ok');
},
};`,
]);

assert.match(stderr, /Thrown at:/);
assert.match(stderr, / at \[eval\]:1:1/);
assert.strictEqual(code, 1);
assert.strictEqual(signal, null);
});
});
20 changes: 20 additions & 0 deletions test/errors/throw-null-traced.mjs
@@ -0,0 +1,20 @@
import { spawnPromisified } from '../common/index.mjs';
import assert from 'node:assert';
import { execPath } from 'node:process';
import { describe, it } from 'node:test';


describe('--trace-uncaught', () => {
it('prints a trace on process exit for uncaught errors', async () => {
const { code, signal, stderr } = await spawnPromisified(execPath, [
'--trace-uncaught',
'--eval',
'throw null;',
]);

assert.match(stderr, /Thrown at:/);
assert.match(stderr, / at \[eval\]:1:1/);
assert.strictEqual(code, 1);
assert.strictEqual(signal, null);
});
});
20 changes: 20 additions & 0 deletions test/errors/throw-undefined-traced.mjs
@@ -0,0 +1,20 @@
import { spawnPromisified } from '../common/index.mjs';
import assert from 'node:assert';
import { execPath } from 'node:process';
import { describe, it } from 'node:test';


describe('--trace-uncaught', () => {
it('prints a trace on process exit for uncaught errors', async () => {
const { code, signal, stderr } = await spawnPromisified(execPath, [
'--trace-uncaught',
'--eval',
'throw undefined;',
]);

assert.match(stderr, /Thrown at:/);
assert.match(stderr, / at \[eval\]:1:1/);
assert.strictEqual(code, 1);
assert.strictEqual(signal, null);
});
});
2 changes: 2 additions & 0 deletions test/message/core_line_numbers.js
@@ -1,5 +1,7 @@
'use strict';
require('../common');
Error.stackTraceLimit = 3;

const punycode = require('punycode');

// This test verifies that line numbers in core modules are reported correctly.
Expand Down
6 changes: 0 additions & 6 deletions test/message/core_line_numbers.out
Expand Up @@ -6,11 +6,5 @@ RangeError: Invalid input
at error (node:punycode:52:8)
at Object.decode (node:punycode:*:*)
at Object.<anonymous> (*test*message*core_line_numbers.js:*:*)
at Module._compile (node:internal/modules/cjs/loader:*:*)
at Module._extensions..js (node:internal/modules/cjs/loader:*:*)
at Module.load (node:internal/modules/cjs/loader:*:*)
at Module._load (node:internal/modules/cjs/loader:*:*)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
at node:internal/main/run_main_module:*:*

Node.js *
2 changes: 2 additions & 0 deletions test/message/error_aggregateTwoErrors.js
Expand Up @@ -2,6 +2,8 @@
'use strict';

require('../common');
Error.stackTraceLimit = 1;

const { aggregateTwoErrors } = require('internal/errors');

const originalError = new Error('original');
Expand Down
25 changes: 3 additions & 22 deletions test/message/error_aggregateTwoErrors.out
@@ -1,34 +1,15 @@
*error_aggregateTwoErrors.js:*
throw aggregateTwoErrors(err, originalError);
^
AggregateError: original
at Object.<anonymous> (*test*message*error_aggregateTwoErrors.js:*:*)
at Module._compile (node:internal/modules/cjs/loader:*:*)
at Module._extensions..js (node:internal/modules/cjs/loader:*:*)
at Module.load (node:internal/modules/cjs/loader:*:*)
at Module._load (node:internal/modules/cjs/loader:*:*)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
at node:internal/main/run_main_module:*:* {
[AggregateError: original] {
code: 'ERR0',
[errors]: [
Error: original
at Object.<anonymous> (*test*message*error_aggregateTwoErrors.js:*:*)
at Module._compile (node:internal/modules/cjs/loader:*:*)
at Module._extensions..js (node:internal/modules/cjs/loader:*:*)
at Module.load (node:internal/modules/cjs/loader:*:*)
at Module._load (node:internal/modules/cjs/loader:*:*)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
at node:internal/main/run_main_module:*:* {
at Object.<anonymous> (/Users/geoffrey/Sites/node/test/message/error_aggregateTwoErrors.js:*:*) {
code: 'ERR0'
},
Error: second error
at Object.<anonymous> (*test*message*error_aggregateTwoErrors.js:*:*)
at Module._compile (node:internal/modules/cjs/loader:*:*)
at Module._extensions..js (node:internal/modules/cjs/loader:*:*)
at Module.load (node:internal/modules/cjs/loader:*:*)
at Module._load (node:internal/modules/cjs/loader:*:*)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
at node:internal/main/run_main_module:*:* {
at Object.<anonymous> (/Users/geoffrey/Sites/node/test/message/error_aggregateTwoErrors.js:*:*) {
code: 'ERR1'
}
]
Expand Down
2 changes: 2 additions & 0 deletions test/message/error_exit.js
Expand Up @@ -21,6 +21,8 @@

'use strict';
require('../common');
Error.stackTraceLimit = 1;

const assert = require('assert');

process.on('exit', function(code) {
Expand Down
8 changes: 1 addition & 7 deletions test/message/error_exit.out
Expand Up @@ -7,13 +7,7 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:

1 !== 2

at Object.<anonymous> (*test*message*error_exit.js:*:*)
at Module._compile (node:internal/modules/cjs/loader:*:*)
at Module._extensions..js (node:internal/modules/cjs/loader:*:*)
at Module.load (node:internal/modules/cjs/loader:*:*)
at Module._load (node:internal/modules/cjs/loader:*:*)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
at node:internal/main/run_main_module:*:* {
at Object.<anonymous> (*test*message*error_exit.js:*:*) {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: 1,
Expand Down
1 change: 1 addition & 0 deletions test/message/error_with_nul.js
@@ -1,5 +1,6 @@
'use strict';
require('../common');
Error.stackTraceLimit = 2;

function test() {
const a = 'abc\0def';
Expand Down
Binary file modified test/message/error_with_nul.out
Binary file not shown.
2 changes: 2 additions & 0 deletions test/message/events_unhandled_error_common_trace.js
@@ -1,5 +1,7 @@
'use strict';
require('../common');
Error.stackTraceLimit = 2;

const EventEmitter = require('events');

function foo() {
Expand Down
10 changes: 0 additions & 10 deletions test/message/events_unhandled_error_common_trace.out
Expand Up @@ -5,18 +5,8 @@ node:events:*
Error: foo:bar
at bar (*events_unhandled_error_common_trace.js:*:*)
at foo (*events_unhandled_error_common_trace.js:*:*)
at Object.<anonymous> (*events_unhandled_error_common_trace.js:*:*)
at Module._compile (node:internal/modules/cjs/loader:*:*)
at Module._extensions..js (node:internal/modules/cjs/loader:*:*)
at Module.load (node:internal/modules/cjs/loader:*:*)
at Module._load (node:internal/modules/cjs/loader:*:*)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
at node:internal/main/run_main_module:*:*
Emitted 'error' event at:
at quux (*events_unhandled_error_common_trace.js:*:*)
at Object.<anonymous> (*events_unhandled_error_common_trace.js:*:*)
at Module._compile (node:internal/modules/cjs/loader:*:*)
[... lines matching original stack trace ...]
at node:internal/main/run_main_module:*:*

Node.js *
2 changes: 2 additions & 0 deletions test/message/events_unhandled_error_nexttick.js
@@ -1,5 +1,7 @@
'use strict';
require('../common');
Error.stackTraceLimit = 1;

const EventEmitter = require('events');
const er = new Error();
process.nextTick(() => {
Expand Down
7 changes: 0 additions & 7 deletions test/message/events_unhandled_error_nexttick.out
Expand Up @@ -4,14 +4,7 @@ node:events:*

Error
at Object.<anonymous> (*events_unhandled_error_nexttick.js:*:*)
at Module._compile (node:internal/modules/cjs/loader:*:*)
at Module._extensions..js (node:internal/modules/cjs/loader:*:*)
at Module.load (node:internal/modules/cjs/loader:*:*)
at Module._load (node:internal/modules/cjs/loader:*:*)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
at node:internal/main/run_main_module:*:*
Emitted 'error' event at:
at *events_unhandled_error_nexttick.js:*:*
at process.processTicksAndRejections (node:internal/process/task_queues:*:*)

Node.js *
2 changes: 2 additions & 0 deletions test/message/events_unhandled_error_sameline.js
@@ -1,4 +1,6 @@
'use strict';
require('../common');
Error.stackTraceLimit = 1;

const EventEmitter = require('events');
new EventEmitter().emit('error', new Error());
9 changes: 0 additions & 9 deletions test/message/events_unhandled_error_sameline.out
Expand Up @@ -4,16 +4,7 @@ node:events:*

Error
at Object.<anonymous> (*events_unhandled_error_sameline.js:*:*)
at Module._compile (node:internal/modules/cjs/loader:*:*)
at Module._extensions..js (node:internal/modules/cjs/loader:*:*)
at Module.load (node:internal/modules/cjs/loader:*:*)
at Module._load (node:internal/modules/cjs/loader:*:*)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
at node:internal/main/run_main_module:*:*
Emitted 'error' event at:
at Object.<anonymous> (*events_unhandled_error_sameline.js:*:*)
at Module._compile (node:internal/modules/cjs/loader:*:*)
[... lines matching original stack trace ...]
at node:internal/main/run_main_module:*:*

Node.js *
2 changes: 2 additions & 0 deletions test/message/events_unhandled_error_subclass.js
@@ -1,5 +1,7 @@
'use strict';
require('../common');
Error.stackTraceLimit = 1;

const EventEmitter = require('events');
class Foo extends EventEmitter {}
new Foo().emit('error', new Error());
9 changes: 0 additions & 9 deletions test/message/events_unhandled_error_subclass.out
Expand Up @@ -4,16 +4,7 @@ node:events:*

Error
at Object.<anonymous> (*events_unhandled_error_subclass.js:*:*)
at Module._compile (node:internal/modules/cjs/loader:*:*)
at Module._extensions..js (node:internal/modules/cjs/loader:*:*)
at Module.load (node:internal/modules/cjs/loader:*:*)
at Module._load (node:internal/modules/cjs/loader:*:*)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
at node:internal/main/run_main_module:*:*
Emitted 'error' event on Foo instance at:
at Object.<anonymous> (*events_unhandled_error_subclass.js:*:*)
at Module._compile (node:internal/modules/cjs/loader:*:*)
[... lines matching original stack trace ...]
at node:internal/main/run_main_module:*:*

Node.js *
2 changes: 2 additions & 0 deletions test/message/if-error-has-good-stack.js
@@ -1,6 +1,8 @@
'use strict';

require('../common');
Error.stackTraceLimit = 4;

const assert = require('assert');

let err;
Expand Down
16 changes: 2 additions & 14 deletions test/message/if-error-has-good-stack.out
Expand Up @@ -10,26 +10,14 @@ AssertionError [ERR_ASSERTION]: ifError got unwanted exception: test error
at c (*if-error-has-good-stack.js:*:*)
at b (*if-error-has-good-stack.js:*:*)
at a (*if-error-has-good-stack.js:*:*)
at Object.<anonymous> (*if-error-has-good-stack.js:*:*)
at Module._compile (node:internal/modules/cjs/loader:*:*)
at Module._extensions..js (node:internal/modules/cjs/loader:*:*)
at Module.load (node:internal/modules/cjs/loader:*:*)
at Module._load (node:internal/modules/cjs/loader:*:*)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
at node:internal/main/run_main_module:*:* {
at Object.<anonymous> (*if-error-has-good-stack.js:*:*) {
generatedMessage: false,
code: 'ERR_ASSERTION',
actual: Error: test error
at c (*if-error-has-good-stack.js:*:*)
at b (*if-error-has-good-stack.js:*:*)
at a (*if-error-has-good-stack.js:*:*)
at Object.<anonymous> (*if-error-has-good-stack.js:*:*)
at Module._compile (node:internal/modules/cjs/loader:*:*)
at Module._extensions..js (node:internal/modules/cjs/loader:*:*)
at Module.load (node:internal/modules/cjs/loader:*:*)
at Module._load (node:internal/modules/cjs/loader:*:*)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
at node:internal/main/run_main_module:*:*
at Object.<anonymous> (*if-error-has-good-stack.js:*:*),
expected: null,
operator: 'ifError'
}
Expand Down
1 change: 1 addition & 0 deletions test/message/source_map_disabled_by_api.js
Expand Up @@ -2,6 +2,7 @@

'use strict';
require('../common');
Error.stackTraceLimit = 5;

process.setSourceMapsEnabled(false);

Expand Down
10 changes: 0 additions & 10 deletions test/message/source_map_disabled_by_api.out
Expand Up @@ -4,19 +4,9 @@ Error: an error!
at functionB (*enclosing-call-site-min.js:1:60)
at functionA (*enclosing-call-site-min.js:1:26)
at Object.<anonymous> (*enclosing-call-site-min.js:1:199)
at Module._compile (node:internal/modules/cjs/loader:*)
at Module._extensions..js (node:internal/modules/cjs/loader:*)
at Module.load (node:internal/modules/cjs/loader:*)
at Module._load (node:internal/modules/cjs/loader:*)
at Module.require (node:internal/modules/cjs/loader:*)
Error: an error!
at functionD (*enclosing-call-site.js:16:17)
at functionC (*enclosing-call-site.js:10:3)
at functionB (*enclosing-call-site.js:6:3)
at functionA (*enclosing-call-site.js:2:3)
at Object.<anonymous> (*enclosing-call-site.js:24:3)
at Module._compile (node:internal/modules/cjs/loader:*)
at Module._extensions..js (node:internal/modules/cjs/loader:*)
at Module.load (node:internal/modules/cjs/loader:*)
at Module._load (node:internal/modules/cjs/loader:*)
at Module.require (node:internal/modules/cjs/loader:*)
1 change: 1 addition & 0 deletions test/message/source_map_enabled_by_api.js
@@ -1,5 +1,6 @@
'use strict';
require('../common');
Error.stackTraceLimit = 5;

process.setSourceMapsEnabled(true);

Expand Down
10 changes: 0 additions & 10 deletions test/message/source_map_enabled_by_api.out
Expand Up @@ -4,19 +4,9 @@ Error: an error!
at functionB (*enclosing-call-site.js:6:3)
at functionA (*enclosing-call-site.js:2:3)
at Object.<anonymous> (*enclosing-call-site.js:24:3)
at Module._compile (node:internal/modules/cjs/loader:*)
at Module._extensions..js (node:internal/modules/cjs/loader:*)
at Module.load (node:internal/modules/cjs/loader:*)
at Module._load (node:internal/modules/cjs/loader:*)
at Module.require (node:internal/modules/cjs/loader:*)
Error: an error!
at functionD (*enclosing-call-site-min.js:1:156)
at functionC (*enclosing-call-site-min.js:1:97)
at functionB (*enclosing-call-site-min.js:1:60)
at functionA (*enclosing-call-site-min.js:1:26)
at Object.<anonymous> (*enclosing-call-site-min.js:1:199)
at Module._compile (node:internal/modules/cjs/loader:*)
at Module._extensions..js (node:internal/modules/cjs/loader:*)
at Module.load (node:internal/modules/cjs/loader:*)
at Module._load (node:internal/modules/cjs/loader:*)
at Module.require (node:internal/modules/cjs/loader:*)
2 changes: 2 additions & 0 deletions test/message/source_map_enclosing_function.js
Expand Up @@ -2,4 +2,6 @@

'use strict';
require('../common');
Error.stackTraceLimit = 5;

require('../fixtures/source-map/enclosing-call-site-min.js');
5 changes: 0 additions & 5 deletions test/message/source_map_enclosing_function.out
Expand Up @@ -8,10 +8,5 @@ Error: an error!
at functionB (*enclosing-call-site.js:6:3)
at functionA (*enclosing-call-site.js:2:3)
at Object.<anonymous> (*enclosing-call-site.js:24:3)
at Module._compile (node:internal/modules/cjs/loader:*)
at Module._extensions..js (node:internal/modules/cjs/loader:*)
at Module.load (node:internal/modules/cjs/loader:*)
at Module._load (node:internal/modules/cjs/loader:*)
at Module.require (node:internal/modules/cjs/loader:*)

Node.js *
2 changes: 2 additions & 0 deletions test/message/source_map_eval.js
Expand Up @@ -2,6 +2,8 @@

'use strict';
require('../common');
Error.stackTraceLimit = 3;

const fs = require('fs');

const content = fs.readFileSync(require.resolve('../fixtures/source-map/tabs.js'), 'utf8');
Expand Down

0 comments on commit 3e255df

Please sign in to comment.