Skip to content

Commit

Permalink
Handle errors that are not Error instances
Browse files Browse the repository at this point in the history
Reviewed By: @sahrens

Differential Revision: D1799587
  • Loading branch information
frantic authored and facebook-github-bot-7 committed Sep 24, 2015
1 parent 88b101b commit 34d57af
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions Libraries/JavaScriptAppEngine/Initialization/ExceptionsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down

0 comments on commit 34d57af

Please sign in to comment.