Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 098a311

Browse filesBrowse files
bnoordhuisrvagg
authored andcommitted
util: move .decorateErrorStack to internal/util
Move the method that was added in commit 8ca412b from earlier this month from lib/util.js to lib/internal/util.js. Avoids exposing a method that we may not wish to expose just yet, seeing how it relies on implementation details. PR-URL: #4026 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 8988e1e commit 098a311
Copy full SHA for 098a311

File tree

Expand file treeCollapse file tree

4 files changed

+32
-27
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+32
-27
lines changed
Open diff view settings
Collapse file

‎lib/internal/util.js‎

Copy file name to clipboardExpand all lines: lib/internal/util.js
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,21 @@ exports._deprecate = function(fn, msg) {
5757

5858
return deprecated;
5959
};
60+
61+
exports.decorateErrorStack = function decorateErrorStack(err) {
62+
if (!(exports.isError(err) && err.stack))
63+
return;
64+
65+
const arrow = exports.getHiddenValue(err, 'arrowMessage');
66+
67+
if (arrow)
68+
err.stack = arrow + err.stack;
69+
};
70+
71+
exports.isError = function isError(e) {
72+
return exports.objectToString(e) === '[object Error]' || e instanceof Error;
73+
};
74+
75+
exports.objectToString = function objectToString(o) {
76+
return Object.prototype.toString.call(o);
77+
};
Collapse file

‎lib/repl.js‎

Copy file name to clipboardExpand all lines: lib/repl.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
'use strict';
2323

2424
const internalModule = require('internal/module');
25+
const internalUtil = require('internal/util');
2526
const util = require('util');
2627
const inherits = util.inherits;
2728
const Stream = require('stream');
@@ -276,7 +277,7 @@ function REPLServer(prompt,
276277
self._domain.on('error', function(e) {
277278
debug('domain error');
278279
const top = replMap.get(self);
279-
util.decorateErrorStack(e);
280+
internalUtil.decorateErrorStack(e);
280281
top.outputStream.write((e.stack || e) + '\n');
281282
top.lineParser.reset();
282283
top.bufferedCommand = '';
Collapse file

‎lib/util.js‎

Copy file name to clipboardExpand all lines: lib/util.js
+3-18Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ const Buffer = require('buffer').Buffer;
55
const internalUtil = require('internal/util');
66
const binding = process.binding('util');
77

8+
const isError = internalUtil.isError;
9+
const objectToString = internalUtil.objectToString;
10+
811
var Debug;
912

1013
const formatRegExp = /%[sdj%]/g;
@@ -680,9 +683,6 @@ function isDate(d) {
680683
}
681684
exports.isDate = isDate;
682685

683-
function isError(e) {
684-
return objectToString(e) === '[object Error]' || e instanceof Error;
685-
}
686686
exports.isError = isError;
687687

688688
function isFunction(arg) {
@@ -698,10 +698,6 @@ exports.isPrimitive = isPrimitive;
698698

699699
exports.isBuffer = Buffer.isBuffer;
700700

701-
function objectToString(o) {
702-
return Object.prototype.toString.call(o);
703-
}
704-
705701

706702
function pad(n) {
707703
return n < 10 ? '0' + n.toString(10) : n.toString(10);
@@ -883,14 +879,3 @@ exports._exceptionWithHostPort = function(err,
883879
}
884880
return ex;
885881
};
886-
887-
888-
exports.decorateErrorStack = function(err) {
889-
if (!(isError(err) && err.stack))
890-
return;
891-
892-
const arrow = internalUtil.getHiddenValue(err, 'arrowMessage');
893-
894-
if (arrow)
895-
err.stack = arrow + err.stack;
896-
};
Collapse file
+9-8Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1+
// Flags: --expose_internals
12
'use strict';
23
const common = require('../common');
34
const assert = require('assert');
4-
const util = require('util');
5+
const internalUtil = require('internal/util');
56

67
assert.doesNotThrow(function() {
7-
util.decorateErrorStack();
8-
util.decorateErrorStack(null);
9-
util.decorateErrorStack(1);
10-
util.decorateErrorStack(true);
8+
internalUtil.decorateErrorStack();
9+
internalUtil.decorateErrorStack(null);
10+
internalUtil.decorateErrorStack(1);
11+
internalUtil.decorateErrorStack(true);
1112
});
1213

1314
// Verify that a stack property is not added to non-Errors
1415
const obj = {};
15-
util.decorateErrorStack(obj);
16+
internalUtil.decorateErrorStack(obj);
1617
assert.strictEqual(obj.stack, undefined);
1718

1819
// Verify that the stack is decorated when possible
@@ -23,13 +24,13 @@ try {
2324
} catch (e) {
2425
err = e;
2526
assert(!/var foo bar;/.test(err.stack));
26-
util.decorateErrorStack(err);
27+
internalUtil.decorateErrorStack(err);
2728
}
2829

2930
assert(/var foo bar;/.test(err.stack));
3031

3132
// Verify that the stack is unchanged when there is no arrow message
3233
err = new Error('foo');
3334
const originalStack = err.stack;
34-
util.decorateErrorStack(err);
35+
internalUtil.decorateErrorStack(err);
3536
assert.strictEqual(originalStack, err.stack);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.