GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — util: add decorateErrorStack() · nodejs/node@8ca412b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • util.js
  • test/parallel
    • test-util-decorate-error-stack.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/util.js‎

Copy file name to clipboardExpand all lines: lib/util.js
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,3 +899,14 @@ exports._exceptionWithHostPort = function(err,
899899
}
900900
return ex;
901901
};
902+
903+
904+
exports.decorateErrorStack = function(err) {
905+
if (!(isError(err) && err.stack))
906+
return;
907+
908+
const arrow = internalUtil.getHiddenValue(err, 'arrowMessage');
909+
910+
if (arrow)
911+
err.stack = arrow + err.stack;
912+
};
Collapse file

‎test/parallel/test-util-decorate-error-stack.js‎

Copy file name to clipboard
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const util = require('util');
5+
6+
assert.doesNotThrow(function() {
7+
util.decorateErrorStack();
8+
util.decorateErrorStack(null);
9+
util.decorateErrorStack(1);
10+
util.decorateErrorStack(true);
11+
});
12+
13+
// Verify that a stack property is not added to non-Errors
14+
const obj = {};
15+
util.decorateErrorStack(obj);
16+
assert.strictEqual(obj.stack, undefined);
17+
18+
// Verify that the stack is decorated when possible
19+
let err;
20+
21+
try {
22+
require('../fixtures/syntax/bad_syntax');
23+
} catch (e) {
24+
err = e;
25+
assert(!/var foo bar;/.test(err.stack));
26+
util.decorateErrorStack(err);
27+
}
28+
29+
assert(/var foo bar;/.test(err.stack));
30+
31+
// Verify that the stack is unchanged when there is no arrow message
32+
err = new Error('foo');
33+
const originalStack = err.stack;
34+
util.decorateErrorStack(err);
35+
assert.strictEqual(originalStack, err.stack);

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.