From 607d0d443e768264d0865f73d7a58f5153bb34bb Mon Sep 17 00:00:00 2001 From: Vignesh Mohankumar Date: Mon, 1 May 2023 15:32:05 -0400 Subject: [PATCH] fix: filter errors with OneKey in stack (#6477) * fix: filter errors with OneKey in stack * check stack --- src/tracing/errors.test.ts | 13 ++++++++++--- src/tracing/errors.ts | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/tracing/errors.test.ts b/src/tracing/errors.test.ts index 59091376f7..e292c757ee 100644 --- a/src/tracing/errors.test.ts +++ b/src/tracing/errors.test.ts @@ -43,13 +43,20 @@ describe('filterKnownErrors', () => { describe('OneKey', () => { it('filter OneKey errors (macOS users)', () => { const originalException = new Error() - originalException.name = 'xd.(/Applications/OneKey.app/Contents/Resources/static/preload.js)' + originalException.stack = ` + SyntaxError: Unexpected token u in JSON at position 0 + at JSON.parse() + at _d._handleAccountChange(/Applications/OneKey.app/Contents/Resources/static/preload.js:2:1634067) + ` expect(filterKnownErrors(ERROR, { originalException })).toBeNull() }) it('filter OneKey errors (Windows users)', () => { const originalException = new Error() - originalException.name = - 'yd.(C:\\Users\\xyz\\AppData\\Local\\Programs\\OneKey\\resources\\static\\preload.js)' + originalException.stack = ` + SyntaxError: Unexpected token u in JSON at position 0 + at JSON.parse() + vd._handleAccountChange(C:\\Users\\example\\AppData\\Local\\Programs\\OneKey\\resources\\static\\preload.js:2:1626130 + ` expect(filterKnownErrors(ERROR, { originalException })).toBeNull() }) }) diff --git a/src/tracing/errors.ts b/src/tracing/errors.ts index 27cf92af96..893613e0f8 100644 --- a/src/tracing/errors.ts +++ b/src/tracing/errors.ts @@ -89,7 +89,7 @@ export const filterKnownErrors: Required['beforeSend'] = (event: * Errors coming from OneKey (a desktop wallet) can be ignored for now. * These errors are either application-specific, or they will be thrown separately outside of OneKey. */ - if (error.name.match(/OneKey/i)) return null + if (error.stack?.match(/OneKey/i)) return null /* * Content security policy 'unsafe-eval' errors can be filtered out because there are expected failures.