Skip to content

Commit

Permalink
Merge pull request #841 from bstell/master
Browse files Browse the repository at this point in the history
Add an error report for when delete IDB fails.
  • Loading branch information
bstell committed Nov 5, 2015
2 parents a084662 + 0e95863 commit 44d4728
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 20 deletions.
23 changes: 19 additions & 4 deletions run_time/src/gae_server/www/js/tachyfont/incrementalfont.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ tachyfont.IncrementalFont.Error_ = {
NOT_USING_PERSISTED_DATA: '41',
FINGERPRINT_MISMATCH: '42',
CHARS_PER_SEGMENT: '43',
DELETE_IDB: '44',
END: '00'
};

Expand Down Expand Up @@ -391,16 +392,30 @@ tachyfont.IncrementalFont.obj_.prototype.dropDb_ = function() {
tachyfont.IncrementalFont.obj_.prototype.accessDb_ = function(dropDb) {
// Close the database if it is open.
this.closeDb_();
var weight = this.fontInfo.getWeight();
var dbName = this.getDbName_();
this.getIDB_ = goog.Promise.resolve()
.then(function() {
if (dropDb) {
return tachyfont.Persist.deleteDatabase(this.getDbName_(),
this.fontInfo.getWeight());
return tachyfont.Persist.deleteDatabase(dbName, weight)
.thenCatch(function() {
tachyfont.IncrementalFont.reportError_(
tachyfont.IncrementalFont.Error_.DELETE_IDB, weight,
'accessDb');
return goog.Promise.reject();
});

}
}.bind(this))
.then(function() {
return tachyfont.Persist.openIndexedDB(this.getDbName_(),
this.fontInfo.getWeight());
return tachyfont.Persist.openIndexedDB(dbName, weight)
.thenCatch(function() {
tachyfont.IncrementalFont.reportError_(
tachyfont.IncrementalFont.Error_.OPEN_IDB, weight,
'accessDb');
return goog.Promise.reject('failed to open IDB');
});

}.bind(this));

return this.getIDB_;
Expand Down
34 changes: 18 additions & 16 deletions run_time/src/gae_server/www/js/tachyfont/tachyfont.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,26 @@ tachyfont.delayedReportError_ = function(obj) {
};


/**
* Report any uncaught errors.
*
* @param {Event} error The error information.
* @private
*/
tachyfont.windowOnError_ = function(error) {
var errorObj = {};
errorObj['message'] = error.error;
errorObj['url'] = error.filename;
errorObj['lineNumber'] = error.lineno;
tachyfont.reportError_(tachyfont.Error_.WINDOW_ON_ERROR, errorObj);
};

if (window.addEventListener) {
/**
* Report any uncaught errors.
*
* @param {Event} error The error information.
* @private
*/
tachyfont.windowOnError_ = function(error) {
var errorObj = {};
errorObj['message'] = error['message'];
errorObj['filename'] = error['filename'];
errorObj['lineno'] = error['lineno'];
errorObj['colno'] = error['colno'];
if (error.error) {
errorObj['stack'] = error['error']['stack'].substring(0, 1000);
}
var errorStr = JSON.stringify(errorObj);
tachyfont.reportError_(tachyfont.Error_.WINDOW_ON_ERROR, errorStr);
};
window.addEventListener('error', tachyfont.windowOnError_, false);
} else if (window.attachEvent) { // for versions previous to IE9
window.attachEvent('onerror', tachyfont.windowOnError_);
}

if (goog.DEBUG) {
Expand Down

0 comments on commit 44d4728

Please sign in to comment.