Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reviewed By: davidaurelio Differential Revision: D3981005 fbshipit-source-id: 3c95e62177f78785c7f971dd632126dbfb83746b
- Loading branch information
Showing
3 changed files
with
72 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,30 +13,40 @@ | |
* before any of the modules, this ErrorUtils must be defined (and the handler | ||
* set) globally before requiring anything. | ||
*/ | ||
|
||
/* eslint strict:0 */ | ||
var ErrorUtils = { | ||
_inGuard: 0, | ||
_globalHandler: null, | ||
const _inGuard = 0; | ||
|
||
/** | ||
* This is the error handler that is called when we encounter an exception | ||
* when loading a module. This will report any errors encountered before | ||
* ExceptionsManager is configured. | ||
*/ | ||
const _globalHandler = function onError(e) { | ||
This comment has been minimized.
Sorry, something went wrong.
trabianmatt
|
||
throw e; | ||
}; | ||
|
||
const ErrorUtils = { | ||
setGlobalHandler: function(fun) { | ||
ErrorUtils._globalHandler = fun; | ||
_globalHandler = fun; | ||
}, | ||
getGlobalHandler: function() { | ||
return ErrorUtils._globalHandler; | ||
return _globalHandler; | ||
}, | ||
reportError: function(error) { | ||
ErrorUtils._globalHandler && ErrorUtils._globalHandler(error); | ||
_globalHandler && _globalHandler(error); | ||
}, | ||
reportFatalError: function(error) { | ||
ErrorUtils._globalHandler && ErrorUtils._globalHandler(error, true); | ||
_globalHandler && _globalHandler(error, true); | ||
}, | ||
applyWithGuard: function(fun, context, args) { | ||
try { | ||
ErrorUtils._inGuard++; | ||
_inGuard++; | ||
return fun.apply(context, args); | ||
} catch (e) { | ||
ErrorUtils.reportError(e); | ||
} finally { | ||
ErrorUtils._inGuard--; | ||
_inGuard--; | ||
} | ||
}, | ||
applyWithGuardIfNeeded: function(fun, context, args) { | ||
|
@@ -47,7 +57,7 @@ var ErrorUtils = { | |
} | ||
}, | ||
inGuard: function() { | ||
return ErrorUtils._inGuard; | ||
return _inGuard; | ||
}, | ||
guard: function(fun, name, context) { | ||
if (typeof fun !== 'function') { | ||
|
@@ -70,18 +80,5 @@ var ErrorUtils = { | |
return guarded; | ||
} | ||
}; | ||
global.ErrorUtils = ErrorUtils; | ||
|
||
/** | ||
* This is the error handler that is called when we encounter an exception | ||
* when loading a module. This will report any errors encountered before | ||
* ExceptionsManager is configured. | ||
*/ | ||
function setupErrorGuard() { | ||
var onError = function(e) { | ||
throw e; | ||
}; | ||
global.ErrorUtils.setGlobalHandler(onError); | ||
} | ||
|
||
setupErrorGuard(); | ||
global.ErrorUtils = ErrorUtils; |
Show Flow complain here?. Is it worth bringing back
(console: any)
? or maybe console defined asany
globally?I'm currently using Flow 0.34 and thinking of submitting a PR to get rid of 3 errors it spits (it sees assigning to console.error as a contravariant (write) use, because previously it identified it as covariant (read))