Handle errors that are not `Error` instances

Reviewed By: @sahrens

Differential Revision: D1799587
This commit is contained in:
Alex Kotliarskyi 2015-09-23 17:11:35 -07:00 committed by facebook-github-bot-7
parent 88b101bb3e
commit 34d57afc32
1 changed files with 11 additions and 10 deletions

View File

@ -19,15 +19,9 @@ var stringifySafe = require('stringifySafe');
var sourceMapPromise;
type Exception = {
sourceURL: string;
line: number;
message: string;
}
var exceptionID = 0;
function reportException(e: Exception, isFatal: bool, stack?: any) {
function reportException(e: Error, isFatal: bool, stack?: any) {
var currentExceptionID = ++exceptionID;
if (RCTExceptionsManager) {
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 msg =
'Error: ' + e.message +
'\n stack: \n' + stackToString(stack) +
'\n URL: ' + e.sourceURL +
'\n line: ' + e.line +
'\n URL: ' + (e: any).sourceURL +
'\n line: ' + (e: any).line +
'\n message: ' + e.message;
if (console.errorOriginal) {
console.errorOriginal(msg);