Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(crashlytics): add custom message ability to javascript stack traces #4609

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/crashlytics/e2e/crashlytics.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ describe('crashlytics()', () => {
firebase.crashlytics().recordError(new Error("I'm a teapot!"));
// TODO verify stack obj
});

it('accepts optional jsErrorName', async () => {
firebase
.crashlytics()
.recordError(
new Error("I'm a teapot!"),
'This message will display in crashlytics dashboard',
);
// TODO verify stack obj
});
});

describe('sendUnsentReports()', () => {
Expand Down
14 changes: 13 additions & 1 deletion packages/crashlytics/lib/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,25 @@ import { isError, once } from '@react-native-firebase/app/lib/common';
import tracking from 'promise/setimmediate/rejection-tracking';
import StackTrace from 'stacktrace-js';

export function createNativeErrorObj(error, stackFrames, isUnhandledRejection) {
export function createNativeErrorObj(error, stackFrames, isUnhandledRejection, jsErrorName) {
const nativeObj = {};

nativeObj.message = `${error.message}`;
nativeObj.isUnhandledRejection = isUnhandledRejection;

nativeObj.frames = [];

if (jsErrorName) {
// Option to fix crashlytics display and alerting. You can add an error name to the recordError function
nativeObj.frames.push({
src: '<unknown>',
line: 0,
col: 0,
fn: '<unknown>',
file: jsErrorName,
});
}

for (let i = 0; i < stackFrames.length; i++) {
const { columnNumber, lineNumber, fileName, functionName, source } = stackFrames[i];
let fileNameParsed = '<unknown>';
Expand Down
3 changes: 2 additions & 1 deletion packages/crashlytics/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ export namespace FirebaseCrashlyticsTypes {
* ```
*
* @param error Expects an instance of Error; e.g. classes that extend Error will also be supported.
* @param jsErrorName Optional string containing Javascript error name
*/
recordError(error: Error): void;
recordError(error: Error, jsErrorName?: string): void;
/**
* Enqueues any unsent reports on the device to upload to Crashlytics. This method only applies if
* automatic data collection is disabled.
Expand Down
4 changes: 2 additions & 2 deletions packages/crashlytics/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ class FirebaseCrashlyticsModule extends FirebaseModule {
return this.native.setUserId(userId);
}

recordError(error) {
recordError(error, jsErrorName) {
if (isError(error)) {
StackTrace.fromError(error, { offline: true }).then(stackFrames => {
this.native.recordError(createNativeErrorObj(error, stackFrames, false));
this.native.recordError(createNativeErrorObj(error, stackFrames, false, jsErrorName));
});
} else {
console.warn(
Expand Down