Skip to content

Commit 098a311

Browse 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

4 files changed

Lines changed: 32 additions & 27 deletions

File tree

‎lib/internal/util.js‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,21 @@ exports._deprecate = function(fn, msg) {
5757

5858
returndeprecated;
5959
};
60+
61+
exports.decorateErrorStack=functiondecorateErrorStack(err){
62+
if(!(exports.isError(err)&&err.stack))
63+
return;
64+
65+
constarrow=exports.getHiddenValue(err,'arrowMessage');
66+
67+
if(arrow)
68+
err.stack=arrow+err.stack;
69+
};
70+
71+
exports.isError=functionisError(e){
72+
returnexports.objectToString(e)==='[object Error]'||einstanceofError;
73+
};
74+
75+
exports.objectToString=functionobjectToString(o){
76+
returnObject.prototype.toString.call(o);
77+
};

‎lib/repl.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
'use strict';
2323

2424
constinternalModule=require('internal/module');
25+
constinternalUtil=require('internal/util');
2526
constutil=require('util');
2627
constinherits=util.inherits;
2728
constStream=require('stream');
@@ -276,7 +277,7 @@ function REPLServer(prompt,
276277
self._domain.on('error',function(e){
277278
debug('domain error');
278279
consttop=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='';

‎lib/util.js‎

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ const Buffer = require('buffer').Buffer;
55
constinternalUtil=require('internal/util');
66
constbinding=process.binding('util');
77

8+
constisError=internalUtil.isError;
9+
constobjectToString=internalUtil.objectToString;
10+
811
varDebug;
912

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

683-
functionisError(e){
684-
returnobjectToString(e)==='[object Error]'||einstanceofError;
685-
}
686686
exports.isError=isError;
687687

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

699699
exports.isBuffer=Buffer.isBuffer;
700700

701-
functionobjectToString(o){
702-
returnObject.prototype.toString.call(o);
703-
}
704-
705701

706702
functionpad(n){
707703
returnn<10 ? '0'+n.toString(10) : n.toString(10);
@@ -883,14 +879,3 @@ exports._exceptionWithHostPort = function(err,
883879
}
884880
returnex;
885881
};
886-
887-
888-
exports.decorateErrorStack=function(err){
889-
if(!(isError(err)&&err.stack))
890-
return;
891-
892-
constarrow=internalUtil.getHiddenValue(err,'arrowMessage');
893-
894-
if(arrow)
895-
err.stack=arrow+err.stack;
896-
};
Lines 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
constcommon=require('../common');
34
constassert=require('assert');
4-
constutil=require('util');
5+
constinternalUtil=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
constobj={};
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(!/varfoobar;/.test(err.stack));
26-
util.decorateErrorStack(err);
27+
internalUtil.decorateErrorStack(err);
2728
}
2829

2930
assert(/varfoobar;/.test(err.stack));
3031

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

0 commit comments

Comments
 (0)