抛出的异常:
lovefield.js:2113 Uncaught NotFoundError:无法在“IDBDatabase”上执行“事务”:找不到指定的对象存储之一。
伙计们,你们好,我已经与 Lovefied 斗争了很长一段时间,试图初始化我的数据库模式。我已经将所有东西都包装在我怀疑可能存在问题并且没有得到任何东西的 try catch 块中。我已经追踪到引发异常的lovefield函数。scanRowId_
但是,我仍然不知道是什么原因造成的。如果它像丢失表格或丢失字段一样直接,它应该在途中破坏了一些东西。任何想法是什么原因?
附表 1:lovelace 源代码
部分内容为:try { var tx = opt_tx || db.transaction([tableName]); req = tx.objectStore(tableName).openCursor(null, "prev"); } 抓住 (e) { 拒绝(e); 返回; } 是抛出异常的地方。
lf.backstore.IndexedDB.prototype.scanRowId_ = function(opt_tx) {
var tableNames = this.schema_.tables().map(function(table) {
return table.getName();
}), db = this.db_, maxRowId = 0, extractRowId = function(cursor) {
if (this.bundledMode_) {
var page = lf.backstore.Page.deserialize(cursor.value);
return Object.keys(page.getPayload()).reduce(function(prev, cur) {
return Math.max(prev, cur);
}, 0);
}
return cursor.key;
}.bind(this), scanTableRowId = function(tableName) {
return new goog.Promise(function(resolve, reject) {
var req;
try {
var tx = opt_tx || db.transaction([tableName]);
req = tx.objectStore(tableName).openCursor(null, "prev");
} catch (e) {
reject(e);
return;
}
req.onsuccess = function(ev) {
var cursor = ev.target.result;
cursor && (maxRowId = Math.max(maxRowId, extractRowId(cursor)));
resolve(maxRowId);
};
req.onerror = function() {
resolve(maxRowId);
};
});
}, execSequentially = function() {
if (0 == tableNames.length) {
return goog.Promise.resolve();
}
var tableName = tableNames.shift();
return scanTableRowId(tableName).then(execSequentially);
};
return new goog.Promise(function(resolve) {
execSequentially().then(function() {
resolve(maxRowId);
});
});
};
图表 2:构建 db 模式的代码
var buildSchema = function() { schemaBuilder = lf.schema.create(urlConfig.dsName, urlConfig.versionNumber); console.assert(tableSchemas, 'tableSchemas!=null'); console.assert(schemaBuilder, 'schemaBuilder!=null'); angular.forEach(tableSchemas, function(val, key) { var item = tableSchemas[key]; console.assert(item, 'item should not be null'); var tableName = item['tsName']; console.assert(tableName, 'tableName should not be null'); var fields = item['metaRecords']; console.assert(fields, 'fields should not be null'); var table; var isPrimary = ''; try { table = schemaBuilder.createTable(tableName); } catch (error) { console.log('failed to createTable(' + tableName + ')'); console.log(error); } for (var x = 0; x < fields.length; x++) { var field = fields[x]; try { table.addColumn(field['fieldName'], eval(field['dataType'])); } catch (error) { console.log('failed at table.addColumn(' + field['fieldName'] + ',' + eval(field['dataType']) + ')'); console.log(error); } try { if (field['isPrimary'] === '1') { isPrimary = field['fieldName']; } else { table.addNullable([field['fieldName']]); } } catch (error) { console.log('failed at table.addNullable(' + field['fieldName']); console.log(error); } } try { if (isPrimary !== '') { if (isPrimary === 'autoid') { table.addPrimaryKey([isPrimary], true); } else { table.addPrimaryKey([isPrimary]); } } } catch (error) { console.log('failed at table.addPrimaryKey('+ [isPrimary]+')'); console.log(error); } }); // persistservice.setVal('dbInitialized', true); };
图表 3:中断的代码
具体来说,中断发生在承诺返回时。
return schemaBuilder.connect().then(function(db) {
/**
* Instantiates the DB connection (re-entrant).
* @return {!IThenable<!lf.Database>}
*/
var getDbConnection = function() {
if (db_ != null) {
return db_;
}
if (!schemaBuilder) {
buildSchema();
}
return schemaBuilder.connect()
.then(function(db) {
db_ = db;
op = lovefield.op;
fn = lovefield.fn;
lf = lf;
onConnected_();
return db;
});
};
图表 4:堆栈跟踪
未捕获的 NotFoundError:无法在“IDBDatabase”上执行“事务”:未找到指定的对象存储之一。(匿名函数)@
堆栈跟踪:
lovefield.js:2113setTimeout (async)goog.async.throwException @ lovefield.js:2112(anonymous function) @ lovefield.js:2589goog.async.run.processWorkQueue @ lovefield.js:2250Promise.resolve (async)goog.async.run.schedule_ @ lovefield.js:2227goog.async.run @ lovefield.js:2220goog.Promise.scheduleCallbacks_ @ lovefield.js:2515goog.Promise.resolve_ @ lovefield.js:2480(anonymous function) @ lovefield.js:2302(anonymous function) @ lovefield.js:6393goog.Promise @ lovefield.js:2290scanTableRowId @ lovefield.js:6387execSequentially @ lovefield.js:6410(anonymous function) @ lovefield.js:6413goog.Promise @ lovefield.js:2290lf.backstore.IndexedDB.scanRowId_ @ lovefield.js:6412(anonymous function) @ lovefield.js:6316IndexedDB (async)(anonymous function) @ lovefield.js:6301goog.Promise @ lovefield.js:2290lf.backstore.IndexedDB.init @ lovefield.js:6298lf.base.init @ lovefield.js:11246lf.proc.Database.init @ lovefield.js:11548lf.schema.Builder.connect @ lovefield.js:12202getDbConnection @ lovefieldservice.js:181lovefieldService @ lovefieldservice.js:194instantiate @ angular.js:4619(anonymous function) @ angular.js:4459invoke @ angular.js:4604enforcedReturnValue @ angular.js:4443invoke @ angular.js:4604(anonymous function) @ angular.js:4403getService @ angular.js:4550injectionArgs @ angular.js:4574instantiate @ angular.js:4616(anonymous function) @ angular.js:9870(anonymous function) @ angular-ui-router.js:4081invokeLinkFn @ angular.js:9492nodeLinkFn @ angular.js:8978compositeLinkFn @ angular.js:8226publicLinkFn @ angular.js:8106(anonymous function) @ angular.js:8447updateView @ angular-ui-router.js:4021(anonymous function) @ angular-ui-router.js:3959Scope.$broadcast @ angular.js:17143$state.transition.resolved.then.$state.transition @ angular-ui-router.js:3352processQueue @ angular.js:15552(anonymous function) @ angular.js:15568Scope.$eval @ angular.js:16820Scope.$digest @ angular.js:16636Scope.$apply @ angular.js:16928done @ angular.js:11266completeRequest @ angular.js:11464requestLoaded @ angular.js:11405XMLHttpRequest.send (async)(anonymous function) @ angular.js:11442sendReq @ angular.js:11235serverRequest @ angular.js:10945processQueue @ angular.js:15552(anonymous function) @ angular.js:15568Scope.$eval @ angular.js:16820Scope.$digest @ angular.js:16636Scope.$apply @ angular.js:16928bootstrapApply @ angular.js:1694invoke @ angular.js:4604doBootstrap @ angular.js:1692bootstrap @ angular.js:1712angularInit @ angular.js:1606(anonymous function) @ angular.js:30423fire @ jquery.js:3182self.fireWith @ jquery.js:3312jQuery.extend.ready @ jquery.js:3531completed @ jquery.js:3547