From 090b0bb509d4b3a71db9b84096d89effd4e2d865 Mon Sep 17 00:00:00 2001 From: Mike Hardy Date: Thu, 26 Nov 2020 07:17:59 -0500 Subject: [PATCH] fix(app): convert NativeFirebaseError.getStackWithMessage to static to fix crash (#4619) * change instance method to static method to avoid fatal error while parsing error * http error * lint errors Co-authored-by: blashadow --- packages/app/lib/internal/NativeFirebaseError.js | 9 ++++++--- packages/functions/lib/HttpsError.js | 7 ++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/app/lib/internal/NativeFirebaseError.js b/packages/app/lib/internal/NativeFirebaseError.js index 9599652785..b458e51739 100644 --- a/packages/app/lib/internal/NativeFirebaseError.js +++ b/packages/app/lib/internal/NativeFirebaseError.js @@ -59,7 +59,10 @@ export default class NativeFirebaseError extends Error { value: userInfo.nativeErrorMessage || null, }); - this.stack = this.getStackWithMessage(`NativeFirebaseError: ${this.message}`); + this.stack = NativeFirebaseError.getStackWithMessage( + `NativeFirebaseError: ${this.message}`, + this.jsStack, + ); // Unused // this.nativeStackIOS = nativeError.nativeStackIOS; @@ -71,7 +74,7 @@ export default class NativeFirebaseError extends Error { * * @returns {string} */ - getStackWithMessage(message) { - return [message, ...this.jsStack.split('\n').slice(2, 13)].join('\n'); + static getStackWithMessage(message, jsStack) { + return [message, ...jsStack.split('\n').slice(2, 13)].join('\n'); } } diff --git a/packages/functions/lib/HttpsError.js b/packages/functions/lib/HttpsError.js index 306502f617..3c4a6e59d0 100644 --- a/packages/functions/lib/HttpsError.js +++ b/packages/functions/lib/HttpsError.js @@ -15,6 +15,8 @@ * */ +import { NativeFirebaseError } from '@react-native-firebase/app/lib/internal'; + export default class HttpsError extends Error { constructor(code, message, details, nativeErrorInstance) { super(message); @@ -34,6 +36,9 @@ export default class HttpsError extends Error { value: message, }); - this.stack = nativeErrorInstance.getStackWithMessage(`Error: ${this.message}`); + this.stack = NativeFirebaseError.getStackWithMessage( + `Error: ${this.message}`, + nativeErrorInstance.jsStack, + ); } }