Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Lovefield: wrap calls to deserialize rows in object_store getAll with…
Browse files Browse the repository at this point in the history
… try/catch. On error, reject the returned promise by wrapping in lf.Exception.

Add a new dedicated error code for failure to deserialize row.

Errors thrown trying to deserialize corrupt data from IndexedDB were previously uncaught (i.e. https://bugs.chromium.org/p/chromium/issues/detail?id=899446)

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=254751151
  • Loading branch information
freshp86 committed Jun 27, 2019
1 parent 7c63a40 commit 85099ec
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
1 change: 1 addition & 0 deletions dist/error_code.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"359": "LocalStorage is not supported by platform.",
"360": "Not implemented yet.",
"361": "Unable to open IndexedDB database: {0}, {1}. See https://github.com/google/lovefield/blob/master/docs/FAQ.md for possible explanation.",
"362": "Error deserializing row from IndexedDB: {0}, {1}",

"500": "Syntax error",
"501": "Value is not bounded.",
Expand Down
2 changes: 1 addition & 1 deletion dist/lovefield.es6.js.map

Large diffs are not rendered by default.

20 changes: 12 additions & 8 deletions dist/lovefield.js
Original file line number Diff line number Diff line change
Expand Up @@ -4932,10 +4932,10 @@ goog.userAgent.isDocumentModeOrHigher = function(documentMode) {
return Number(goog.userAgent.DOCUMENT_MODE) >= documentMode;
};
goog.userAgent.isDocumentMode = goog.userAgent.isDocumentModeOrHigher;
var JSCompiler_inline_result$jscomp$2;
var doc$jscomp$inline_4 = goog.global.document;
JSCompiler_inline_result$jscomp$2 = doc$jscomp$inline_4 && goog.userAgent.IE ? goog.userAgent.getDocumentMode_() : void 0;
goog.userAgent.DOCUMENT_MODE = JSCompiler_inline_result$jscomp$2;
var JSCompiler_inline_result$jscomp$3;
var doc$jscomp$inline_5 = goog.global.document;
JSCompiler_inline_result$jscomp$3 = doc$jscomp$inline_5 && goog.userAgent.IE ? goog.userAgent.getDocumentMode_() : void 0;
goog.userAgent.DOCUMENT_MODE = JSCompiler_inline_result$jscomp$3;
goog.userAgent.platform = {};
goog.userAgent.platform.determineVersion_ = function() {
if (goog.userAgent.WINDOWS) {
Expand Down Expand Up @@ -7656,10 +7656,14 @@ lf.backstore.ObjectStore.prototype.getAllBulk_ = function() {
}
request.onerror = reject;
request.onsuccess = function() {
var rows = request.result.map(function(rawRow) {
return this.deserializeFn_(rawRow);
}, this);
resolve(rows);
try {
var rows = request.result.map(function(rawRow) {
return this.deserializeFn_(rawRow);
}, this);
resolve(rows);
} catch (e$2) {
reject(new lf.Exception(362, e$2.name, e$2.message));
}
}.bind(this);
}, this);
};
Expand Down
2 changes: 1 addition & 1 deletion dist/lovefield.min.js.map

Large diffs are not rendered by default.

19 changes: 13 additions & 6 deletions lib/backstore/object_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
goog.provide('lf.backstore.ObjectStore');

goog.require('goog.Promise');
goog.require('lf.Exception');
goog.require('lf.Flags');
goog.require('lf.Table');

Expand Down Expand Up @@ -122,12 +123,18 @@ lf.backstore.ObjectStore.prototype.getAllBulk_ = function() {

request.onerror = reject;
request.onsuccess = function() {
var rows = request.result.map(
/** @this {lf.backstore.ObjectStore} */
function(rawRow) {
return this.deserializeFn_(rawRow);
}, this);
resolve(rows);
try {
var rows = request.result.map(
/** @this {lf.backstore.ObjectStore} */
function(rawRow) {
return this.deserializeFn_(rawRow);
},
this);
resolve(rows);
} catch (e) {
// 362: error deserializing row from IndexedDB.
reject(new lf.Exception(362, e.name, e.message));
}
}.bind(this);
}, this);
};
Expand Down

0 comments on commit 85099ec

Please sign in to comment.