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

Commit 6010557

Browse files
committed
fix: improve long-stack-trace stack format detection
1 parent eeaab91 commit 6010557

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

Diff for: lib/zone-spec/long-stack-trace.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const IGNORE_FRAMES: {[k: string]: true} = {};
1515
const creationTrace = '__creationTrace__';
1616
const ERROR_TAG = 'STACKTRACE TRACKING';
1717
const SEP_TAG = '__SEP_TAG__';
18-
let sepTemplate = '';
18+
let sepTemplate: string = SEP_TAG + '@[native]';
1919

2020
class LongStackTrace {
2121
error: Error = getStacktrace();
@@ -137,19 +137,23 @@ function computeIgnoreFrames() {
137137
const frames2 = frames[1];
138138
for (let i = 0; i < frames1.length; i++) {
139139
const frame1 = frames1[i];
140-
const frame2 = frames2[i];
141-
if (!sepTemplate && frame1.indexOf(ERROR_TAG) == -1) {
142-
sepTemplate = frame1.replace(/^(\s*(at)?\s*)([\w\/\<]+)/, '$1' + SEP_TAG);
140+
if (frame1.indexOf(ERROR_TAG) == -1) {
141+
let match = frame1.match(/^\s*at\s+/);
142+
if (match) {
143+
sepTemplate = match[0] + SEP_TAG + ' (http://localhost)';
144+
break;
145+
}
143146
}
147+
}
148+
149+
for (let i = 0; i < frames1.length; i++) {
150+
const frame1 = frames1[i];
151+
const frame2 = frames2[i];
144152
if (frame1 === frame2) {
145153
IGNORE_FRAMES[frame1] = true;
146154
} else {
147155
break;
148156
}
149157
}
150-
if (!sepTemplate) {
151-
// If we could not find it default to this text.
152-
sepTemplate = SEP_TAG + '@[native code]';
153-
}
154158
}
155159
computeIgnoreFrames();

Diff for: test/zone-spec/long-stack-trace-zone.spec.ts

+17-13
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,25 @@ describe('longStackTraceZone', function() {
2828
log = [];
2929
});
3030

31+
function expectElapsed(stack: string, expectedCount: number) {
32+
try {
33+
let actualCount = stack.split('_Elapsed_').length;
34+
if (actualCount !== expectedCount) {
35+
expect(actualCount).toEqual(expectedCount);
36+
console.log(stack);
37+
}
38+
} catch (e) {
39+
expect(e).toBe(null);
40+
}
41+
}
42+
3143
it('should produce long stack traces', function(done) {
3244
lstz.run(function() {
3345
setTimeout(function() {
3446
setTimeout(function() {
3547
setTimeout(function() {
36-
try {
37-
expect(log[0].stack.split('Elapsed').length).toBe(3);
38-
done();
39-
} catch (e) {
40-
expect(e).toBe(null);
41-
}
48+
expectElapsed(log[0].stack, 3);
49+
done();
4250
}, 0);
4351
throw new Error('Hello');
4452
}, 0);
@@ -81,12 +89,8 @@ describe('longStackTraceZone', function() {
8189
fail('should not get here');
8290
});
8391
setTimeout(function() {
84-
try {
85-
expect(log[0].stack.split('Elapsed').length).toBe(5);
86-
done();
87-
} catch (e) {
88-
expect(e).toBe(null);
89-
}
92+
expectElapsed(log[0].stack, 5);
93+
done();
9094
}, 0);
9195
}, 0);
9296
}, 0);
@@ -105,7 +109,7 @@ describe('longStackTraceZone', function() {
105109
promise.catch(function(error) {
106110
// should be able to get long stack trace
107111
const longStackFrames: string = longStackTraceZoneSpec.getLongStackTrace(error);
108-
expect(longStackFrames.split('Elapsed').length).toBe(4);
112+
expectElapsed(longStackFrames, 4);
109113
done();
110114
});
111115
}, 0);

0 commit comments

Comments
 (0)