Skip to content

Commit

Permalink
Include more context in indexedDB error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
GarboMuffin committed Nov 3, 2024
1 parent 11fbd44 commit ac22e7f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/lib/tw-local-backpack-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const getBackpackContents = async ({
return new Promise((resolve, reject) => {
const transaction = db.transaction(STORE_NAME, 'readonly');
transaction.onerror = event => {
reject(new Error(`Transaction error: ${event.target.error}`));
reject(new Error(`Getting contents: ${event.target.error}`));
};
const store = transaction.objectStore(STORE_NAME);
const items = [];
Expand Down Expand Up @@ -133,7 +133,7 @@ const saveBackpackObject = async ({
return new Promise((resolve, reject) => {
const transaction = db.transaction(STORE_NAME, 'readwrite');
transaction.onerror = event => {
reject(new Error(`Transaction error: ${event.target.error}`));
reject(new Error(`Sving object: ${event.target.error}`));
};
const store = transaction.objectStore(STORE_NAME);
const bodyData = base64ToArrayBuffer(body);
Expand Down Expand Up @@ -162,7 +162,7 @@ const deleteBackpackObject = async ({
return new Promise((resolve, reject) => {
const transaction = db.transaction(STORE_NAME, 'readwrite');
transaction.onerror = event => {
reject(new Error(`Transaction error: ${event.target.error}`));
reject(new Error(`Deleting object: ${event.target.error}`));
};
const store = transaction.objectStore(STORE_NAME);
// Convert string IDs to number IDs
Expand All @@ -182,7 +182,7 @@ const updateBackpackObject = async ({
return new Promise((resolve, reject) => {
const transaction = db.transaction(STORE_NAME, 'readwrite');
transaction.onerror = event => {
reject(new Error(`Transaction error: ${event.target.error}`));
reject(new Error(`Updating object: ${event.target.error}`));
};
const store = transaction.objectStore(STORE_NAME);
const getRequest = store.get(id);
Expand Down
16 changes: 8 additions & 8 deletions src/lib/tw-restore-point-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ const removeExtraneousData = transaction => new Promise(resolve => {
const removeExtraneousRestorePoints = () => openDB().then(db => new Promise((resolveTransaction, rejectTransaction) => {
const transaction = db.transaction(ALL_STORES, 'readwrite');
transaction.onerror = event => {
rejectTransaction(new Error(`Transaction error: ${event.target.error}`));
rejectTransaction(new Error(`Removing extraneous: ${event.target.error}`));
};

// Figuring out which restore points to keep and which to remove is non-trivial.
Expand Down Expand Up @@ -311,7 +311,7 @@ const createRestorePoint = (
generateThumbnail(vm).then(thumbnailData => {
const transaction = db.transaction(ALL_STORES, 'readwrite');
transaction.onerror = event => {
rejectTransaction(new Error(`Transaction error: ${event.target.error}`));
rejectTransaction(new Error(`Creating restore point: ${event.target.error}`));
};

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

const metadataStore = transaction.objectStore(METADATA_STORE);
Expand All @@ -415,7 +415,7 @@ 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 = event => {
rejectTransaction(new Error(`Transaction error: ${event.target.error}`));
rejectTransaction(new Error(`Deleting all restore points: ${event.target.error}`));
};

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

const md5ext = `${assetId}.${dataFormat}`;
Expand All @@ -475,7 +475,7 @@ const loadRestorePoint = (vm, id) => openDB().then(db => new Promise((resolvePro
const loadProjectJSON = () => {
const transaction = db.transaction([PROJECT_STORE], 'readonly');
transaction.onerror = event => {
rejectProject(new Error(`Transaction error: ${event.target.error}`));
rejectProject(new Error(`Loading restore point JSON: ${event.target.error}`));
};

const projectStore = transaction.objectStore(PROJECT_STORE);
Expand Down Expand Up @@ -509,7 +509,7 @@ 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 = event => {
reject(new Error(`Transaction error: ${event.target.error}`));
reject(new Error(`Getting all restore points: ${event.target.error}`));
};

/** @type {Metadata[]} */
Expand Down Expand Up @@ -553,7 +553,7 @@ 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 = event => {
reject(new Error(`Transaction error: ${event.target.error}`));
reject(new Error(`Getting thumbnail: ${event.target.error}`));
};

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

0 comments on commit ac22e7f

Please sign in to comment.