mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-05-08 21:23:12 +08:00
[crashlytics] Fixes: #1643, #1848, #1964, #1920, #1884, #1783, #1966, #1940, #1447 Features/Bugs Todo: Capture JS Exceptions with stack traces automatically Capture Unhandled Promise Rejections with stack traces automatically [Android] .crash() not captured in debug due to RN RedBox; see #1921 Support advanced user identifier features [Android] Enable Crashlyics NDK reporting by default (gist) Support toggling native crash logging off/on (e.g. disable in DEV) Support toggling JS crash logging off/on (e.g. disable in DEV) [ios] Static framework support for all modules [ios] Implement CocoaPods Firebase RN modules auto-loader script Implement firebase.json config loader; Android & iOS [tests] Fix false positive tests that catch errors (tests did not check that errors actually threw) [android] Cleanup manifest permissions for all modules [android] Implement Content provider base class [android] Investigate/fix issue where setDataCollectionDefaultEnabled is false by default in Firebase - it disables Crashlytics reporting
162 lines
4.3 KiB
JavaScript
162 lines
4.3 KiB
JavaScript
/* eslint-disable no-console */
|
|
/*
|
|
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this library except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*
|
|
*/
|
|
|
|
import {
|
|
createModuleNamespace,
|
|
FirebaseModule,
|
|
getFirebaseRoot,
|
|
} from '@react-native-firebase/app/lib/internal';
|
|
|
|
import StackTrace from 'stacktrace-js';
|
|
import { isBoolean, isError, isObject, isString } from '@react-native-firebase/common';
|
|
|
|
import version from './version';
|
|
import {
|
|
createNativeErrorObj,
|
|
setGlobalErrorHandler,
|
|
setOnUnhandledPromiseRejectionHandler,
|
|
} from './handlers';
|
|
|
|
const statics = {};
|
|
|
|
const namespace = 'crashlytics';
|
|
|
|
const nativeModuleName = 'RNFBCrashlyticsModule';
|
|
|
|
class FirebaseCrashlyticsModule extends FirebaseModule {
|
|
constructor(...args) {
|
|
super(...args);
|
|
setGlobalErrorHandler(this.native);
|
|
setOnUnhandledPromiseRejectionHandler(this.native);
|
|
this._isCrashlyticsCollectionEnabled = this.native.isCrashlyticsCollectionEnabled;
|
|
}
|
|
|
|
get isCrashlyticsCollectionEnabled() {
|
|
return this._isCrashlyticsCollectionEnabled;
|
|
}
|
|
|
|
crash() {
|
|
this.native.crash();
|
|
}
|
|
|
|
log(message) {
|
|
this.native.log(`${message}`);
|
|
}
|
|
|
|
setAttribute(name, value) {
|
|
if (!isString(name)) {
|
|
throw new Error(
|
|
'firebase.crashlytics().setAttribute(*, _): The supplied property name must be a string.',
|
|
);
|
|
}
|
|
|
|
if (!isString(value)) {
|
|
throw new Error(
|
|
'firebase.crashlytics().setAttribute(_, *): The supplied property value must be a string value.',
|
|
);
|
|
}
|
|
|
|
return this.native.setAttribute(name, value);
|
|
}
|
|
|
|
setAttributes(object) {
|
|
if (!isObject(object)) {
|
|
throw new Error(
|
|
'firebase.crashlytics().setAttributes(*): The supplied arg must be an object of key value strings.',
|
|
);
|
|
}
|
|
|
|
return this.native.setAttributes(object);
|
|
}
|
|
|
|
setUserId(userId) {
|
|
if (!isString(userId)) {
|
|
throw new Error(
|
|
'firebase.crashlytics().setUserId(*): The supplied userId must be a string value.',
|
|
);
|
|
}
|
|
|
|
return this.native.setUserId(userId);
|
|
}
|
|
|
|
setUserName(userName) {
|
|
if (!isString(userName)) {
|
|
throw new Error(
|
|
'firebase.crashlytics().setUserName(*): The supplied userName must be a string value.',
|
|
);
|
|
}
|
|
|
|
return this.native.setUserName(userName);
|
|
}
|
|
|
|
setUserEmail(userEmail) {
|
|
if (!isString(userEmail)) {
|
|
throw new Error(
|
|
'firebase.crashlytics().setUserEmail(*): The supplied userEmail must be a string value.',
|
|
);
|
|
}
|
|
|
|
return this.native.setUserEmail(userEmail);
|
|
}
|
|
|
|
recordError(error) {
|
|
if (isError(error)) {
|
|
StackTrace.fromError(error, { offline: true }).then(stackFrames => {
|
|
this.native.recordError(createNativeErrorObj(error, stackFrames, false));
|
|
});
|
|
} else {
|
|
console.warn(
|
|
'firebase.crashlytics().recordError(*) expects an instance of Error. Non Errors will be ignored.',
|
|
);
|
|
}
|
|
}
|
|
|
|
setCrashlyticsCollectionEnabled(enabled) {
|
|
if (!isBoolean(enabled)) {
|
|
throw new Error(
|
|
`firebase.crashlytics().setCrashlyticsCollectionEnabled(*) 'enabled' must be a boolean.`,
|
|
);
|
|
}
|
|
|
|
this._isCrashlyticsCollectionEnabled = enabled;
|
|
return this.native.setCrashlyticsCollectionEnabled(enabled);
|
|
}
|
|
}
|
|
|
|
// import { SDK_VERSION } from '@react-native-firebase/crashlytics';
|
|
export const SDK_VERSION = version;
|
|
|
|
// import crashlytics from '@react-native-firebase/crashlytics';
|
|
// crashlytics().X(...);
|
|
export default createModuleNamespace({
|
|
statics,
|
|
version,
|
|
namespace,
|
|
nativeModuleName,
|
|
nativeEvents: false,
|
|
hasMultiAppSupport: false,
|
|
hasCustomUrlOrRegionSupport: false,
|
|
ModuleClass: FirebaseCrashlyticsModule,
|
|
});
|
|
|
|
// import crashlytics, { firebase } from '@react-native-firebase/crashlytics';
|
|
// crashlytics().X(...);
|
|
// firebase.crashlytics().X(...);
|
|
export const firebase = getFirebaseRoot();
|
|
firebase.crashlytics();
|