|
| 1 | +import { stackParserFromStackParserOptions } from '@sentry/utils'; |
| 2 | + |
| 3 | +const UNKNOWN_FUNCTION = undefined; |
| 4 | + |
| 5 | +// function createFrame(filename, func, lineno, colno) { |
| 6 | + |
| 7 | +function createFrame(frame) { |
| 8 | + frame.in_app = (frame.filename && !frame.filename.includes('node_modules')) || (!!frame.colno && !!frame.lineno); |
| 9 | + frame.platform = frame.filename.endsWith('.js') ? 'javascript' : 'android'; |
| 10 | + |
| 11 | + return frame; |
| 12 | +} |
| 13 | + |
| 14 | +const nativescriptRegex = |
| 15 | + /^\s*at (?:(.*\).*?|.*?) ?\()?((?:file|native|webpack|<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i; |
| 16 | + |
| 17 | +const nativescriptFunc = line => { |
| 18 | + const parts = nativescriptRegex.exec(line); |
| 19 | + if (parts) { |
| 20 | + return createFrame({ |
| 21 | + filename:parts[2], |
| 22 | + function:parts[1] || UNKNOWN_FUNCTION, |
| 23 | + lineno:parts[3] ? +parts[3] : undefined, |
| 24 | + colno:parts[4] ? +parts[4] : undefined |
| 25 | + }); |
| 26 | + } |
| 27 | + return null; |
| 28 | +}; |
| 29 | + |
| 30 | +const nativescriptLineParser = [30, nativescriptFunc]; |
| 31 | + |
| 32 | +const androidRegex = |
| 33 | + /^\s*(?:(.*\).*?|.*?) ?\()?((?:Native Method|[-a-z]+:)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i; |
| 34 | + |
| 35 | +const androidFunc = line => { |
| 36 | + const parts = androidRegex.exec(line); |
| 37 | + if (parts) { |
| 38 | + let func = UNKNOWN_FUNCTION, mod; |
| 39 | + if (parts[1]) { |
| 40 | + const splitted = parts[1].split('.'); |
| 41 | + func = splitted[splitted.length-1]; |
| 42 | + mod = splitted.slice(0, -1).join('.'); |
| 43 | + } |
| 44 | + return createFrame({ |
| 45 | + filename:parts[2], |
| 46 | + function:func, |
| 47 | + module:mod, |
| 48 | + lineno:parts[3] ? +parts[3] : undefined, |
| 49 | + colno:parts[4] ? +parts[4] : undefined |
| 50 | + }); |
| 51 | + } |
| 52 | + return null; |
| 53 | +}; |
| 54 | + |
| 55 | +const androidLineParser = [50, androidFunc]; |
| 56 | + |
| 57 | +const stackParser = stackParserFromStackParserOptions([nativescriptLineParser, androidLineParser]); |
| 58 | + |
| 59 | +console.log('stackParser', stackParser(`at androidNativeCrashTest(file:///data/data/org.nativescript.demovuesentry/files/app/bundle.js:184:92) |
| 60 | +at invokeWithErrorHandling(file:///data/data/org.nativescript.demovuesentry/files/app/vendor.js:73859:26) |
| 61 | +at invoker(file:///data/data/org.nativescript.demovuesentry/files/app/vendor.js:74513:14) |
| 62 | +at _handleEvent(file:///data/data/org.nativescript.demovuesentry/files/app/vendor.js:23374:37) |
| 63 | +at notify(file:///data/data/org.nativescript.demovuesentry/files/app/vendor.js:23356:24) |
| 64 | +at _emit(file:///data/data/org.nativescript.demovuesentry/files/app/vendor.js:23403:18) |
| 65 | +at ClickListenerImpl.onClick(file:///data/data/org.nativescript.demovuesentry/files/app/vendor.js:33101:19) |
| 66 | +com.nativescript.sentry.ClassExample.helloWorld(ClassExample.java:5) |
| 67 | +com.tns.Runtime.callJSMethodNative(Native Method) |
| 68 | +com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1302) |
| 69 | +com.tns.Runtime.callJSMethodImpl(Runtime.java:1188) |
| 70 | +com.tns.Runtime.callJSMethod(Runtime.java:1175) |
| 71 | +com.tns.Runtime.callJSMethod(Runtime.java:1153) |
| 72 | +com.tns.Runtime.callJSMethod(Runtime.java:1149) |
| 73 | +java.lang.Object_vendor_33094_28_ClickListenerImpl.onClick(Unknown Source:10) |
| 74 | +android.view.View.performClick(View.java:7441) |
| 75 | +android.view.View.performClickInternal(View.java:7418) |
| 76 | +android.view.View.access$3700(View.java:835) |
| 77 | +android.view.View$PerformClick.run(View.java:28676) |
| 78 | +android.os.Handler.handleCallback(Handler.java:938) |
| 79 | +android.os.Handler.dispatchMessage(Handler.java:99) |
| 80 | +android.os.Looper.loopOnce(Looper.java:201) |
| 81 | +android.os.Looper.loop(Looper.java:288) |
| 82 | +android.app.ActivityThread.main(ActivityThread.java:7839) |
| 83 | +java.lang.reflect.Method.invoke(Native Method) |
| 84 | +com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) |
| 85 | +com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)`)); |
0 commit comments