Skip to content

Commit

Permalink
Fix indexedDB error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
GarboMuffin committed Nov 3, 2024
1 parent 78e06ca commit cc490da
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
28 changes: 14 additions & 14 deletions src/lib/tw-local-backpack-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,21 @@ const openDB = () => new Promise((resolve, reject) => {

const request = indexedDB.open(DATABASE_NAME, DATABASE_VERSION);

request.onupgradeneeded = e => {
const db = e.target.result;
request.onupgradeneeded = event => {
const db = event.target.result;
db.createObjectStore(STORE_NAME, {
keyPath: 'id',
autoIncrement: true
});
};

request.onsuccess = e => {
_db = e.target.result;
request.onsuccess = event => {
_db = event.target.result;
resolve(_db);
};

request.onerror = () => {
reject(new Error(`DB error: ${request.error}`));
request.onerror = event => {
reject(new Error(`DB error: ${event.target.error}`));
};
});

Expand All @@ -93,8 +93,8 @@ const getBackpackContents = async ({
const db = await openDB();
return new Promise((resolve, reject) => {
const transaction = db.transaction(STORE_NAME, 'readonly');
transaction.onerror = () => {
reject(new Error(`Transaction error: ${transaction.error}`));
transaction.onerror = event => {
reject(new Error(`Transaction error: ${event.target.error}`));
};
const store = transaction.objectStore(STORE_NAME);
const items = [];
Expand Down Expand Up @@ -132,8 +132,8 @@ const saveBackpackObject = async ({
const db = await openDB();
return new Promise((resolve, reject) => {
const transaction = db.transaction(STORE_NAME, 'readwrite');
transaction.onerror = () => {
reject(new Error(`Transaction error: ${transaction.error}`));
transaction.onerror = event => {
reject(new Error(`Transaction error: ${event.target.error}`));
};
const store = transaction.objectStore(STORE_NAME);
const bodyData = base64ToArrayBuffer(body);
Expand Down Expand Up @@ -161,8 +161,8 @@ const deleteBackpackObject = async ({
const db = await openDB();
return new Promise((resolve, reject) => {
const transaction = db.transaction(STORE_NAME, 'readwrite');
transaction.onerror = () => {
reject(new Error(`Transaction error: ${transaction.error}`));
transaction.onerror = event => {
reject(new Error(`Transaction error: ${event.target.error}`));
};
const store = transaction.objectStore(STORE_NAME);
// Convert string IDs to number IDs
Expand All @@ -181,8 +181,8 @@ const updateBackpackObject = async ({
const db = await openDB();
return new Promise((resolve, reject) => {
const transaction = db.transaction(STORE_NAME, 'readwrite');
transaction.onerror = () => {
reject(new Error(`Transaction error: ${transaction.error}`));
transaction.onerror = event => {
reject(new Error(`Transaction error: ${event.target.error}`));
};
const store = transaction.objectStore(STORE_NAME);
const getRequest = store.get(id);
Expand Down
32 changes: 16 additions & 16 deletions src/lib/tw-restore-point-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ const removeExtraneousData = transaction => new Promise(resolve => {
*/
const removeExtraneousRestorePoints = () => openDB().then(db => new Promise((resolveTransaction, rejectTransaction) => {
const transaction = db.transaction(ALL_STORES, 'readwrite');
transaction.onerror = () => {
rejectTransaction(new Error(`Transaction error: ${transaction.error}`));
transaction.onerror = event => {
rejectTransaction(new Error(`Transaction error: ${event.target.error}`));
};

// Figuring out which restore points to keep and which to remove is non-trivial.
Expand Down Expand Up @@ -310,8 +310,8 @@ const createRestorePoint = (

generateThumbnail(vm).then(thumbnailData => {
const transaction = db.transaction(ALL_STORES, 'readwrite');
transaction.onerror = () => {
rejectTransaction(new Error(`Transaction error: ${transaction.error}`));
transaction.onerror = event => {
rejectTransaction(new Error(`Transaction error: ${event.target.error}`));
};

// Will be generated by database
Expand Down Expand Up @@ -397,8 +397,8 @@ const createRestorePoint = (
*/
const deleteRestorePoint = id => openDB().then(db => new Promise((resolve, reject) => {
const transaction = db.transaction(ALL_STORES, 'readwrite');
transaction.onerror = () => {
reject(new Error(`Transaction error: ${transaction.error}`));
transaction.onerror = event => {
reject(new Error(`Transaction error: ${event.target.error}`));
};

const metadataStore = transaction.objectStore(METADATA_STORE);
Expand All @@ -414,8 +414,8 @@ const deleteRestorePoint = id => openDB().then(db => new Promise((resolve, rejec
*/
const deleteAllRestorePoints = () => openDB().then(db => new Promise((resolveTransaction, rejectTransaction) => {
const transaction = db.transaction(ALL_STORES, 'readwrite');
transaction.onerror = () => {
rejectTransaction(new Error(`Transaction error: ${transaction.error}`));
transaction.onerror = event => {
rejectTransaction(new Error(`Transaction error: ${event.target.error}`));
};

const deleteEverything = async () => {
Expand Down Expand Up @@ -448,8 +448,8 @@ const loadRestorePoint = (vm, id) => openDB().then(db => new Promise((resolvePro
const storageHelper = {
load: (assetType, assetId, dataFormat) => new Promise((resolveFetch, rejectFetch) => {
const transaction = db.transaction([ASSET_STORE], 'readonly');
transaction.onerror = () => {
rejectFetch(new Error(`Transaction error: ${transaction.error}`));
transaction.onerror = event => {
rejectFetch(new Error(`Transaction error: ${event.target.error}`));
};

const md5ext = `${assetId}.${dataFormat}`;
Expand All @@ -474,8 +474,8 @@ const loadRestorePoint = (vm, id) => openDB().then(db => new Promise((resolvePro

const loadProjectJSON = () => {
const transaction = db.transaction([PROJECT_STORE], 'readonly');
transaction.onerror = () => {
rejectProject(new Error(`Transaction error: ${transaction.error}`));
transaction.onerror = event => {
rejectProject(new Error(`Transaction error: ${event.target.error}`));
};

const projectStore = transaction.objectStore(PROJECT_STORE);
Expand Down Expand Up @@ -508,8 +508,8 @@ const loadRestorePoint = (vm, id) => openDB().then(db => new Promise((resolvePro
*/
const getAllRestorePoints = () => openDB().then(db => new Promise((resolve, reject) => {
const transaction = db.transaction([METADATA_STORE], 'readonly');
transaction.onerror = () => {
reject(new Error(`Transaction error: ${transaction.error}`));
transaction.onerror = event => {
reject(new Error(`Transaction error: ${event.target.error}`));
};

/** @type {Metadata[]} */
Expand Down Expand Up @@ -552,8 +552,8 @@ const getAllRestorePoints = () => openDB().then(db => new Promise((resolve, reje
*/
const getThumbnail = id => openDB().then(db => new Promise((resolve, reject) => {
const transaction = db.transaction([THUMBNAIL_STORE], 'readonly');
transaction.onerror = () => {
reject(new Error(`Transaction error: ${transaction.error}`));
transaction.onerror = event => {
reject(new Error(`Transaction error: ${event.target.error}`));
};

const thumbnailStore = transaction.objectStore(THUMBNAIL_STORE);
Expand Down

0 comments on commit cc490da

Please sign in to comment.