Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 7133de0

Browse files
committed
feat: add stackFramesFilter to longStackTraceZone
1 parent 39b1513 commit 7133de0

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

long-stack-trace-zone.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ Zone.Stacktrace = function (e) {
88
this._e = e;
99
};
1010
Zone.Stacktrace.prototype.get = function () {
11-
var frames = this._e.stack.split('\n');
12-
13-
var markerIndex;
14-
for (var markerIndex = frames.length - 1; markerIndex >= 0; markerIndex -= 1) {
15-
if (frames[markerIndex].indexOf('marker@') === 0) {
16-
return frames.slice(markerIndex+1).join('\n');
17-
}
11+
if (zone.stackFramesFilter) {
12+
return this._e.stack.
13+
split('\n').
14+
filter(zone.stackFramesFilter).
15+
join('\n');
1816
}
1917
return this._e.stack;
2018
}
@@ -46,8 +44,15 @@ Zone.getStacktrace = function () {
4644

4745
Zone.longStackTraceZone = {
4846
getLongStacktrace: function (exception) {
49-
var trace = [exception.stack];
47+
var trace = [];
5048
var zone = this;
49+
if (zone.stackFramesFilter) {
50+
trace.push(exception.stack.split('\n').
51+
filter(zone.stackFramesFilter).
52+
join('\n'));
53+
} else {
54+
trace.push(exception.stack);
55+
}
5156
var now = Date.now();
5257
while (zone && zone.constructedAtException) {
5358
trace.push(
@@ -59,6 +64,10 @@ Zone.longStackTraceZone = {
5964
return trace.join('\n');
6065
},
6166

67+
stackFramesFilter: function (line) {
68+
return line.indexOf('zone.js') === -1;
69+
},
70+
6271
onError: function (exception) {
6372
var reporter = this.reporter || console.log.bind(console);
6473
reporter(exception.toString());

test/long-stack-trace-zone.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,22 @@ describe('Zone.patch', function () {
2828
expect(log[0]).toBe('Error: hello');
2929
expect(log[1].split('--- ').length).toBe(4);
3030
});
31+
32+
33+
it('should filter based on stackFramesFilter', function () {
34+
lstz.fork({
35+
stackFramesFilter: function (line) {
36+
return line.indexOf('jasmine.js') === -1;
37+
}
38+
}).run(function () {
39+
setTimeout(function () {
40+
setTimeout(function () {
41+
throw new Error('hello');
42+
}, 0);
43+
}, 0);
44+
});
45+
46+
jasmine.Clock.tick(0);
47+
expect(log[1]).not.toContain('jasmine.js');
48+
});
3149
});

0 commit comments

Comments
 (0)