Skip to content

Commit 72116e2

Browse files
kriszypclaude
andcommitted
fix: guard against corrupt __dbis__ entries crashing startup
Null-check decoded values from attributesDbi.getRange() in both initStores and the table() function — RecordEncoder.decode returns null on error (e.g. mismatched structon typedStructs after a version mismatch), and the subsequent property accesses (value.name, value.isPrimaryKey) would throw. Corrupt entries are now silently skipped; RecordEncoder already logs the decode error. Also guard databases.system before the 'in' check in checkIfInstallIsSupported: if getDatabases() throws mid-scan, loadedDatabases is already true but databases.system is never populated, producing a TypeError on the next startup. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent f847836 commit 72116e2

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

dataLayer/hdbInfoController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ function checkIfInstallIsSupported(dataVNum) {
237237
'In order to upgrade to this version, you must do a fresh install. If you need support, ' +
238238
`please contact ${hdbTerms.HDB_SUPPORT_ADDRESS}`;
239239

240-
if (!('hdb_info' in tableLoader.databases.system)) {
240+
if (!tableLoader.databases.system || !('hdb_info' in tableLoader.databases.system)) {
241241
console.log(errMsg);
242242
throw new Error(errMsg);
243243
}

resources/databases.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ function initStores(
506506

507507
for (const result of attributesDbi.getRange({ start: false })) {
508508
const { key, value } = result as { key: string; value: any };
509+
if (value == null) continue;
509510
let [tableName, attribute_name] = key.toString().split('/');
510511
if (attribute_name === '') {
511512
// primary key
@@ -1104,6 +1105,7 @@ export function table<TableResourceType>(tableDefinition: TableDefinition): Tabl
11041105
Table.dbisDB = attributesDbi;
11051106
const indicesToRemove = [];
11061107
for (const { key, value } of attributesDbi.getRange({ start: true })) {
1108+
if (value == null) continue;
11071109
let [attributeTableName, attribute_name] = key.toString().split('/');
11081110
if (attribute_name === '') attribute_name = value.name; // primary key
11091111
if (attribute_name) {

0 commit comments

Comments
 (0)