UNPKG

3.05 kBJavaScriptView Raw
1Object.defineProperty(exports, '__esModule', { value: true });
2
3const utils = require('@sentry/utils');
4
5/** Rewrite event frames paths */
6class RewriteFrames {
7 /**
8 * @inheritDoc
9 */
10 static __initStatic() {this.id = 'RewriteFrames';}
11
12 /**
13 * @inheritDoc
14 */
15 __init() {this.name = RewriteFrames.id;}
16
17 /**
18 * @inheritDoc
19 */
20
21 /**
22 * @inheritDoc
23 */
24 __init2() {this._prefix = 'app:///';}
25
26 /**
27 * @inheritDoc
28 */
29 constructor(options = {}) {;RewriteFrames.prototype.__init.call(this);RewriteFrames.prototype.__init2.call(this);RewriteFrames.prototype.__init3.call(this);
30 if (options.root) {
31 this._root = options.root;
32 }
33 if (options.prefix) {
34 this._prefix = options.prefix;
35 }
36 if (options.iteratee) {
37 this._iteratee = options.iteratee;
38 }
39 }
40
41 /**
42 * @inheritDoc
43 */
44 setupOnce(addGlobalEventProcessor, getCurrentHub) {
45 addGlobalEventProcessor(event => {
46 const self = getCurrentHub().getIntegration(RewriteFrames);
47 if (self) {
48 return self.process(event);
49 }
50 return event;
51 });
52 }
53
54 /** JSDoc */
55 process(originalEvent) {
56 let processedEvent = originalEvent;
57
58 if (originalEvent.exception && Array.isArray(originalEvent.exception.values)) {
59 processedEvent = this._processExceptionsEvent(processedEvent);
60 }
61
62 return processedEvent;
63 }
64
65 /**
66 * @inheritDoc
67 */
68 __init3() {this._iteratee = (frame) => {
69 if (!frame.filename) {
70 return frame;
71 }
72 // Check if the frame filename begins with `/` or a Windows-style prefix such as `C:\`
73 const isWindowsFrame = /^[A-Z]:\\/.test(frame.filename);
74 const startsWithSlash = /^\//.test(frame.filename);
75 if (isWindowsFrame || startsWithSlash) {
76 const filename = isWindowsFrame
77 ? frame.filename
78 .replace(/^[A-Z]:/, '') // remove Windows-style prefix
79 .replace(/\\/g, '/') // replace all `\\` instances with `/`
80 : frame.filename;
81 const base = this._root ? utils.relative(this._root, filename) : utils.basename(filename);
82 frame.filename = `${this._prefix}${base}`;
83 }
84 return frame;
85 };}
86
87 /** JSDoc */
88 _processExceptionsEvent(event) {
89 try {
90 return {
91 ...event,
92 exception: {
93 ...event.exception,
94 // The check for this is performed inside `process` call itself, safe to skip here
95 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
96 values: event.exception.values.map(value => ({
97 ...value,
98 ...(value.stacktrace && { stacktrace: this._processStacktrace(value.stacktrace) }),
99 })),
100 },
101 };
102 } catch (_oO) {
103 return event;
104 }
105 }
106
107 /** JSDoc */
108 _processStacktrace(stacktrace) {
109 return {
110 ...stacktrace,
111 frames: stacktrace && stacktrace.frames && stacktrace.frames.map(f => this._iteratee(f)),
112 };
113 }
114} RewriteFrames.__initStatic();
115
116exports.RewriteFrames = RewriteFrames;
117//# sourceMappingURL=rewriteframes.js.map