Permalink
Browse files

Make goog.debug.normalizeErrorObject always work on Firefox 2

Firefox 2 sometimes throws an error when accessing the `lineNumber` or
`filename` property on an Error object
Contributed by Ivan Kozik.
Fixes issue 261.



Revision created by MOE tool push_codebase.

R=pupius
DELTA=45  (23 added, 0 deleted, 22 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=296


git-svn-id: http://closure-library.googlecode.com/svn/trunk@626 0b95b8e8-c90f-11de-9d4f-f947ee5921c8
  • Loading branch information...
1 parent 43f237a commit a091567bc29a7a6ee7861e1c5609fa01233a3366 nicksantos@google.com committed Jan 18, 2011
Showing with 45 additions and 22 deletions.
  1. +1 −0 AUTHORS
  2. +44 −22 closure/goog/debug/debug.js
View
@@ -9,3 +9,4 @@ Bjorn Tipling <bjorn.tipling@gmail.com>
SameGoal LLC <help@samegoal.com>
Guido Tapia <guido.tapia@gmail.com>
Ilia Mirkin <ibmirkin@gmail.com>
+Ivan Kozik <ivan.kozik@gmail.com>
@@ -199,28 +199,50 @@ goog.debug.exposeException = function(err, opt_fn) {
*/
goog.debug.normalizeErrorObject = function(err) {
var href = goog.getObjectByName('window.location.href');
- return (typeof err == 'string') ?
- {
- 'message': err,
- 'name': 'Unknown error',
- 'lineNumber': 'Not available',
- 'fileName': href,
- 'stack': 'Not available'
- } :
-
- // The IE Error object contains only the name and the message
- // The Safari Error object uses the line and sourceURL fields
- (!err.lineNumber || !err.fileName || !err.stack) ?
- {
- 'message': err.message,
- 'name': err.name,
- 'lineNumber': err.lineNumber || err.line || 'Not available',
- 'fileName': err.fileName || err.filename || err.sourceURL || href,
- 'stack': err.stack || 'Not available'
- } :
-
- // Standards error object
- err;
+ if (goog.isString(err)) {
+ return {
+ 'message': err,
+ 'name': 'Unknown error',
+ 'lineNumber': 'Not available',
+ 'fileName': href,
+ 'stack': 'Not available'
+ };
+ }
+
+ var lineNumber, fileName;
+ var threwError = false;
+
+ try {
+ lineNumber = err.lineNumber || err.line || 'Not available';
+ } catch (e) {
+ // Firefox 2 sometimes throws an error when accessing 'lineNumber':
+ // Message: Permission denied to get property UnnamedClass.lineNumber
+ lineNumber = 'Not available';
+ threwError = true;
+ }
+
+ try {
+ fileName = err.fileName || err.filename || err.sourceURL || href;
+ } catch (e) {
+ // Firefox 2 may also throw an error when accessing 'filename'.
+ fileName = 'Not available';
+ threwError = true;
+ }
+
+ // The IE Error object contains only the name and the message.
+ // The Safari Error object uses the line and sourceURL fields.
+ if (threwError || !err.lineNumber || !err.fileName || !err.stack) {
+ return {
+ 'message': err.message,
+ 'name': err.name,
+ 'lineNumber': lineNumber,
+ 'fileName': fileName,
+ 'stack': err.stack || 'Not available'
+ };
+ }
+
+ // Standards error object
+ return err;
};

0 comments on commit a091567

Please sign in to comment.