Skip to content

Commit

Permalink
fixup! lib: avoid mutating Error.stackTraceLimit when Error is fr…
Browse files Browse the repository at this point in the history
…ozen
  • Loading branch information
aduh95 committed Apr 14, 2021
1 parent ca2f28b commit 0788c7c
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Flags: --expose-internals
'use strict';
require('../common');
const assert = require('assert');
const { E, SystemError, codes } = require('internal/errors');

let stackTraceLimit;
Reflect.defineProperty(Error, 'stackTraceLimit', {
get() { return stackTraceLimit; },
set(value) { stackTraceLimit = value; },
});

E('ERR_TEST', 'custom message', SystemError);
const { ERR_TEST } = codes;

const ctx = {
code: 'ETEST',
message: 'code message',
syscall: 'syscall_test',
path: '/str',
dest: '/str2'
};
assert.throws(
() => { throw new ERR_TEST(ctx); },
{
code: 'ERR_TEST',
name: 'SystemError',
info: ctx,
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Flags: --expose-internals
'use strict';
require('../common');
const assert = require('assert');
const { E, SystemError, codes } = require('internal/errors');

delete Error.stackTraceLimit;
Object.seal(Error);

E('ERR_TEST', 'custom message', SystemError);
const { ERR_TEST } = codes;

const ctx = {
code: 'ETEST',
message: 'code message',
syscall: 'syscall_test',
path: '/str',
dest: '/str2'
};
assert.throws(
() => { throw new ERR_TEST(ctx); },
{
code: 'ERR_TEST',
name: 'SystemError',
info: ctx,
}
);
26 changes: 26 additions & 0 deletions test/parallel/test-errors-systemerror-stackTraceLimit-deleted.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Flags: --expose-internals
'use strict';
require('../common');
const assert = require('assert');
const { E, SystemError, codes } = require('internal/errors');

delete Error.stackTraceLimit;

E('ERR_TEST', 'custom message', SystemError);
const { ERR_TEST } = codes;

const ctx = {
code: 'ETEST',
message: 'code message',
syscall: 'syscall_test',
path: '/str',
dest: '/str2'
};
assert.throws(
() => { throw new ERR_TEST(ctx); },
{
code: 'ERR_TEST',
name: 'SystemError',
info: ctx,
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Flags: --expose-internals
'use strict';
require('../common');
const assert = require('assert');
const { E, SystemError, codes } = require('internal/errors');

Reflect.defineProperty(Error, 'stackTraceLimit', { get() { return 0; } });

E('ERR_TEST', 'custom message', SystemError);
const { ERR_TEST } = codes;

const ctx = {
code: 'ETEST',
message: 'code message',
syscall: 'syscall_test',
path: '/str',
dest: '/str2'
};
assert.throws(
() => { throw new ERR_TEST(ctx); },
{
code: 'ERR_TEST',
name: 'SystemError',
info: ctx,
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Flags: --expose-internals
'use strict';
require('../common');
const assert = require('assert');
const { E, SystemError, codes } = require('internal/errors');

Reflect.defineProperty(Error, 'stackTraceLimit', {
writable: false,
value: Error.stackTraceLimit,
});

E('ERR_TEST', 'custom message', SystemError);
const { ERR_TEST } = codes;

const ctx = {
code: 'ETEST',
message: 'code message',
syscall: 'syscall_test',
path: '/str',
dest: '/str2'
};
assert.throws(
() => { throw new ERR_TEST(ctx); },
{
code: 'ERR_TEST',
name: 'SystemError',
info: ctx,
}
);

0 comments on commit 0788c7c

Please sign in to comment.