Add spec for ExceptionsManager (#24900)

Summary:
Part of #24875, adds a spec for ExceptionsManager

## Changelog

[General] [Added] - TM Add spec for ExceptionsManager
Pull Request resolved: https://github.com/facebook/react-native/pull/24900

Reviewed By: fkgozali

Differential Revision: D15434006

Pulled By: RSNara

fbshipit-source-id: 1a505744a84c0c4ac3a9fac6c91a391fbd8a9f46
This commit is contained in:
Michał Pierzchała
2019-05-22 13:10:24 -07:00
committed by Facebook Github Bot
parent 65b10b350e
commit 8ea749ad3e
9 changed files with 66 additions and 23 deletions
+1 -6
View File
@@ -10,12 +10,7 @@
'use strict';
export type StackFrame = {
column: ?number,
file: string,
lineNumber: number,
methodName: string,
};
import type {StackFrame} from '../NativeExceptionsManager';
export type ExtendedError = Error & {
framesToPop?: number,
@@ -17,7 +17,7 @@ import NativeSourceCode from '../../NativeModules/specs/NativeSourceCode';
// Avoid requiring fetch on load of this module; see symbolicateStackTrace
let fetch;
import type {StackFrame} from './parseErrorStack';
import type {StackFrame} from '../NativeExceptionsManager';
function isSourcedFromDisk(sourcePath: string): boolean {
return !/^http/.test(sourcePath) && /[\\/]/.test(sourcePath);
+12 -7
View File
@@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
* @flow strict-local
*/
'use strict';
@@ -24,21 +24,25 @@ const INTERNAL_CALLSITES_REGEX = new RegExp(
*/
let exceptionID = 0;
function reportException(e: ExtendedError, isFatal: boolean) {
const {ExceptionsManager} = require('../BatchedBridge/NativeModules');
if (ExceptionsManager) {
const NativeExceptionsManager = require('./NativeExceptionsManager').default;
if (NativeExceptionsManager) {
const parseErrorStack = require('./Devtools/parseErrorStack');
const stack = parseErrorStack(e);
const currentExceptionID = ++exceptionID;
const message =
e.jsEngine == null ? e.message : `${e.message}, js engine: ${e.jsEngine}`;
if (isFatal) {
ExceptionsManager.reportFatalException(
NativeExceptionsManager.reportFatalException(
message,
stack,
currentExceptionID,
);
} else {
ExceptionsManager.reportSoftException(message, stack, currentExceptionID);
NativeExceptionsManager.reportSoftException(
message,
stack,
currentExceptionID,
);
}
if (__DEV__) {
const symbolicateStackTrace = require('./Devtools/symbolicateStackTrace');
@@ -50,7 +54,7 @@ function reportException(e: ExtendedError, isFatal: boolean) {
frame.file &&
frame.file.match(INTERNAL_CALLSITES_REGEX) === null,
);
ExceptionsManager.updateExceptionMessage(
NativeExceptionsManager.updateExceptionMessage(
message,
stackWithoutInternalCallsites,
currentExceptionID,
@@ -67,7 +71,7 @@ function reportException(e: ExtendedError, isFatal: boolean) {
}
declare var console: typeof console & {
_errorOriginal: Function,
_errorOriginal: typeof console.error,
reportErrorsAsExceptions: boolean,
};
@@ -80,6 +84,7 @@ function handleException(e: Error, isFatal: boolean) {
// case, so if you ended up here trying to trace an error, look for
// `throw '<error message>'` somewhere in your codebase.
if (!e.message) {
// $FlowFixMe - cannot reassign constant, explanation above
e = new Error(e);
}
if (console._errorOriginal) {
+43
View File
@@ -0,0 +1,43 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/
'use strict';
import type {TurboModule} from 'RCTExport';
import * as TurboModuleRegistry from 'TurboModuleRegistry';
export type StackFrame = {|
column: ?number,
file: string,
lineNumber: number,
methodName: string,
|};
export interface Spec extends TurboModule {
+reportFatalException: (
message: string,
stack: Array<StackFrame>,
exceptionId: number,
) => void;
+reportSoftException: (
message: string,
stack: Array<StackFrame>,
exceptionId: number,
) => void;
+updateExceptionMessage: (
message: string,
stack: Array<StackFrame>,
exceptionId: number,
) => void;
// Android only
+dismissRedbox: () => void;
}
export default TurboModuleRegistry.getEnforcing<Spec>('ExceptionsManager');
+5 -5
View File
@@ -81,11 +81,11 @@ Error: ${e.message}`;
) {
NativeRedBox.dismiss();
} else {
const RCTExceptionsManager = require('../BatchedBridge/NativeModules')
.ExceptionsManager;
RCTExceptionsManager &&
RCTExceptionsManager.dismissRedbox &&
RCTExceptionsManager.dismissRedbox();
const NativeExceptionsManager = require('../Core/NativeExceptionsManager')
.default;
NativeExceptionsManager &&
NativeExceptionsManager.dismissRedbox &&
NativeExceptionsManager.dismissRedbox();
}
});
@@ -12,7 +12,7 @@
const symbolicateStackTrace = require('../../Core/Devtools/symbolicateStackTrace');
import type {StackFrame} from '../../Core/Devtools/parseErrorStack';
import type {StackFrame} from '../../Core/NativeExceptionsManager';
type CacheKey = string;
@@ -11,7 +11,7 @@
'use strict';
import type {StackFrame} from '../../../Core/Devtools/parseErrorStack';
import type {StackFrame} from '../../../Core/NativeExceptionsManager';
jest.mock('../../../Core/Devtools/symbolicateStackTrace');
@@ -11,7 +11,7 @@
'use strict';
import type {StackFrame} from '../../../Core/Devtools/parseErrorStack';
import type {StackFrame} from '../../../Core/NativeExceptionsManager';
jest.mock('../YellowBoxSymbolication');
@@ -17,7 +17,7 @@ const YellowBoxPressable = require('./YellowBoxPressable');
const YellowBoxStyle = require('./YellowBoxStyle');
import type {PressEvent} from '../../Types/CoreEventTypes';
import type {StackFrame} from '../../Core/Devtools/parseErrorStack';
import type {StackFrame} from '../../Core/NativeExceptionsManager';
type Props = $ReadOnly<{|
frame: StackFrame,