2017-11-23 17:29:40 +00:00
|
|
|
/**
|
|
|
|
* @flow
|
|
|
|
* Crash Reporting representation wrapper
|
|
|
|
*/
|
|
|
|
import ModuleBase from '../../utils/ModuleBase';
|
2018-01-05 17:20:02 +00:00
|
|
|
import { getNativeModule } from '../../utils/native';
|
2017-11-23 17:29:40 +00:00
|
|
|
|
2018-02-14 13:00:19 +00:00
|
|
|
import type App from '../core/app';
|
2017-11-23 17:29:40 +00:00
|
|
|
import type { FirebaseError } from '../../types';
|
2017-03-10 14:17:37 +00:00
|
|
|
|
2018-01-03 20:00:38 +00:00
|
|
|
export const MODULE_NAME = 'RNFirebaseCrash';
|
|
|
|
export const NAMESPACE = 'crash';
|
2017-08-17 16:58:28 +00:00
|
|
|
|
2018-01-03 20:00:38 +00:00
|
|
|
export default class Crash extends ModuleBase {
|
2018-01-05 17:20:02 +00:00
|
|
|
constructor(app: App) {
|
|
|
|
super(app, {
|
2018-01-03 20:00:38 +00:00
|
|
|
moduleName: MODULE_NAME,
|
2018-01-09 17:31:00 +00:00
|
|
|
multiApp: false,
|
2017-11-21 23:37:05 +00:00
|
|
|
hasShards: false,
|
2018-01-03 20:00:38 +00:00
|
|
|
namespace: NAMESPACE,
|
|
|
|
});
|
2017-05-25 22:39:06 +00:00
|
|
|
}
|
|
|
|
|
2017-06-12 13:26:56 +00:00
|
|
|
/**
|
|
|
|
* Enables/Disables crash reporting
|
|
|
|
* @param enabled
|
|
|
|
*/
|
|
|
|
setCrashCollectionEnabled(enabled: boolean): void {
|
2018-01-05 17:20:02 +00:00
|
|
|
getNativeModule(this).setCrashCollectionEnabled(enabled);
|
2017-06-12 13:26:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether or not crash reporting is currently enabled
|
|
|
|
* @returns {Promise.<boolean>}
|
|
|
|
*/
|
|
|
|
isCrashCollectionEnabled(): Promise<boolean> {
|
2018-01-05 17:20:02 +00:00
|
|
|
return getNativeModule(this).isCrashCollectionEnabled();
|
2017-06-12 13:26:56 +00:00
|
|
|
}
|
|
|
|
|
2017-03-10 14:17:37 +00:00
|
|
|
/**
|
|
|
|
* Logs a message that will appear in a subsequent crash report.
|
|
|
|
* @param {string} message
|
|
|
|
*/
|
|
|
|
log(message: string): void {
|
2018-01-05 17:20:02 +00:00
|
|
|
getNativeModule(this).log(message);
|
2017-03-10 14:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Logs a message that will appear in a subsequent crash report as well as in logcat.
|
|
|
|
* NOTE: Android only functionality. iOS will just log the message.
|
|
|
|
* @param {string} message
|
|
|
|
* @param {number} level
|
|
|
|
* @param {string} tag
|
|
|
|
*/
|
|
|
|
logcat(level: number, tag: string, message: string): void {
|
2018-01-05 17:20:02 +00:00
|
|
|
getNativeModule(this).logcat(level, tag, message);
|
2017-03-10 14:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates a crash report for the given message. This method should be used for unexpected
|
|
|
|
* exceptions where recovery is not possible.
|
|
|
|
* NOTE: on iOS, this will cause the app to crash as it's the only way to ensure the exception
|
|
|
|
* gets sent to Firebase. Otherwise it just gets lost as a log message.
|
2017-03-17 15:41:25 +00:00
|
|
|
* @param {Error} error
|
|
|
|
* @param maxStackSize
|
2017-03-10 14:17:37 +00:00
|
|
|
*/
|
2017-04-04 16:58:20 +00:00
|
|
|
report(error: FirebaseError, maxStackSize: number = 10): void {
|
2017-06-26 05:30:17 +00:00
|
|
|
if (!error || !error.message) return;
|
2017-03-17 15:41:25 +00:00
|
|
|
|
|
|
|
let errorMessage = `Message: ${error.message}\r\n`;
|
|
|
|
|
|
|
|
if (error.code) {
|
|
|
|
errorMessage = `${errorMessage}Code: ${error.code}\r\n`;
|
|
|
|
}
|
|
|
|
|
|
|
|
const stackRows = error.stack.split('\n');
|
|
|
|
errorMessage = `${errorMessage}\r\nStack: \r\n`;
|
|
|
|
for (let i = 0, len = stackRows.length; i < len; i++) {
|
|
|
|
if (i === maxStackSize) break;
|
|
|
|
errorMessage = `${errorMessage} - ${stackRows[i]}\r\n`;
|
|
|
|
}
|
|
|
|
|
2018-01-05 17:20:02 +00:00
|
|
|
getNativeModule(this).report(errorMessage);
|
2017-03-10 14:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-23 17:29:40 +00:00
|
|
|
|
|
|
|
export const statics = {};
|