Fatal Exception Message Truncation in React Native

For some reason React Native truncates fatal error message to 75 chars which is a bit of a bummer when you’re looking at a Crashlytics report like this:

“Unhandled JS Exception: undefined is not an object (evaluating ‘this.props….”

We had line number data from the callstack but still, what was it that was “undefined”?

"not clear what was undefined. could be any of this, this.props, this.props.rowData, and this.props.rowData.campaign"

Fortunately, you can override this behavior and retain the exact same error handling using the following most of which is copied directly from RCTAssert.m:

    RCTSetFatalHandler(^(NSError * error) {
        @try {
            // Use 255 chars here instead of FB's 75.
            NSString *message = RCTFormatError([error localizedDescription], error.userInfo[RCTJSStackTraceKey], 255);
            [NSException raise:RCTFatalExceptionName format:@"%@", message];
        } @catch (NSException *e) {}

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.