Handle errors that are not `Error` instances
Reviewed By: @sahrens Differential Revision: D1799587
This commit is contained in:
parent
88b101bb3e
commit
34d57afc32
|
@ -19,15 +19,9 @@ var stringifySafe = require('stringifySafe');
|
||||||
|
|
||||||
var sourceMapPromise;
|
var sourceMapPromise;
|
||||||
|
|
||||||
type Exception = {
|
|
||||||
sourceURL: string;
|
|
||||||
line: number;
|
|
||||||
message: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
var exceptionID = 0;
|
var exceptionID = 0;
|
||||||
|
|
||||||
function reportException(e: Exception, isFatal: bool, stack?: any) {
|
function reportException(e: Error, isFatal: bool, stack?: any) {
|
||||||
var currentExceptionID = ++exceptionID;
|
var currentExceptionID = ++exceptionID;
|
||||||
if (RCTExceptionsManager) {
|
if (RCTExceptionsManager) {
|
||||||
if (!stack) {
|
if (!stack) {
|
||||||
|
@ -53,13 +47,20 @@ function reportException(e: Exception, isFatal: bool, stack?: any) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleException(e: Exception, isFatal: boolean) {
|
function handleException(e: Error, isFatal: boolean) {
|
||||||
|
// Workaround for reporting errors caused by `throw 'some string'`
|
||||||
|
// Unfortunately there is no way to figure out the stacktrace in this
|
||||||
|
// case, so if you ended up here trying to trace an error, look for
|
||||||
|
// `throw '<error message>'` somewhere in your codebase.
|
||||||
|
if (!e.message) {
|
||||||
|
e = new Error(e);
|
||||||
|
}
|
||||||
var stack = parseErrorStack(e);
|
var stack = parseErrorStack(e);
|
||||||
var msg =
|
var msg =
|
||||||
'Error: ' + e.message +
|
'Error: ' + e.message +
|
||||||
'\n stack: \n' + stackToString(stack) +
|
'\n stack: \n' + stackToString(stack) +
|
||||||
'\n URL: ' + e.sourceURL +
|
'\n URL: ' + (e: any).sourceURL +
|
||||||
'\n line: ' + e.line +
|
'\n line: ' + (e: any).line +
|
||||||
'\n message: ' + e.message;
|
'\n message: ' + e.message;
|
||||||
if (console.errorOriginal) {
|
if (console.errorOriginal) {
|
||||||
console.errorOriginal(msg);
|
console.errorOriginal(msg);
|
||||||
|
|
Loading…
Reference in New Issue