1 | import { relative, basename } from '@sentry/utils';
|
2 |
|
3 |
|
4 | class RewriteFrames {
|
5 | |
6 |
|
7 |
|
8 | static __initStatic() {this.id = 'RewriteFrames';}
|
9 |
|
10 | |
11 |
|
12 |
|
13 | __init() {this.name = RewriteFrames.id;}
|
14 |
|
15 | |
16 |
|
17 |
|
18 |
|
19 | |
20 |
|
21 |
|
22 | __init2() {this._prefix = 'app:///';}
|
23 |
|
24 | |
25 |
|
26 |
|
27 | constructor(options = {}) {RewriteFrames.prototype.__init.call(this);RewriteFrames.prototype.__init2.call(this);RewriteFrames.prototype.__init3.call(this);
|
28 | if (options.root) {
|
29 | this._root = options.root;
|
30 | }
|
31 | if (options.prefix) {
|
32 | this._prefix = options.prefix;
|
33 | }
|
34 | if (options.iteratee) {
|
35 | this._iteratee = options.iteratee;
|
36 | }
|
37 | }
|
38 |
|
39 | |
40 |
|
41 |
|
42 | setupOnce(addGlobalEventProcessor, getCurrentHub) {
|
43 | addGlobalEventProcessor(event => {
|
44 | const self = getCurrentHub().getIntegration(RewriteFrames);
|
45 | if (self) {
|
46 | return self.process(event);
|
47 | }
|
48 | return event;
|
49 | });
|
50 | }
|
51 |
|
52 |
|
53 | process(originalEvent) {
|
54 | let processedEvent = originalEvent;
|
55 |
|
56 | if (originalEvent.exception && Array.isArray(originalEvent.exception.values)) {
|
57 | processedEvent = this._processExceptionsEvent(processedEvent);
|
58 | }
|
59 |
|
60 | return processedEvent;
|
61 | }
|
62 |
|
63 | |
64 |
|
65 |
|
66 | __init3() {this._iteratee = (frame) => {
|
67 | if (!frame.filename) {
|
68 | return frame;
|
69 | }
|
70 |
|
71 | const isWindowsFrame = /^[A-Z]:\\/.test(frame.filename);
|
72 | const startsWithSlash = /^\//.test(frame.filename);
|
73 | if (isWindowsFrame || startsWithSlash) {
|
74 | const filename = isWindowsFrame
|
75 | ? frame.filename
|
76 | .replace(/^[A-Z]:/, '')
|
77 | .replace(/\\/g, '/')
|
78 | : frame.filename;
|
79 | const base = this._root ? relative(this._root, filename) : basename(filename);
|
80 | frame.filename = `${this._prefix}${base}`;
|
81 | }
|
82 | return frame;
|
83 | };}
|
84 |
|
85 |
|
86 | _processExceptionsEvent(event) {
|
87 | try {
|
88 | return {
|
89 | ...event,
|
90 | exception: {
|
91 | ...event.exception,
|
92 |
|
93 |
|
94 | values: event.exception.values.map(value => ({
|
95 | ...value,
|
96 | ...(value.stacktrace && { stacktrace: this._processStacktrace(value.stacktrace) }),
|
97 | })),
|
98 | },
|
99 | };
|
100 | } catch (_oO) {
|
101 | return event;
|
102 | }
|
103 | }
|
104 |
|
105 |
|
106 | _processStacktrace(stacktrace) {
|
107 | return {
|
108 | ...stacktrace,
|
109 | frames: stacktrace && stacktrace.frames && stacktrace.frames.map(f => this._iteratee(f)),
|
110 | };
|
111 | }
|
112 | } RewriteFrames.__initStatic();
|
113 |
|
114 | export { RewriteFrames };
|
115 |
|