improve error reporting

This commit is contained in:
Florian Dold 2019-11-21 10:43:40 +01:00
parent 035b3fdae2
commit f797f16e2f
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
3 changed files with 33 additions and 6 deletions

View File

@ -1,6 +1,6 @@
{
"name": "idb-bridge",
"version": "0.0.11",
"version": "0.0.12",
"description": "IndexedDB implementation that uses SQLite3 as storage",
"main": "./build/index.js",
"types": "./build/index.d.ts",

View File

@ -32,6 +32,7 @@ import {
InvalidStateError,
InvalidAccessError,
ConstraintError,
DataError,
} from "./util/errors";
import BTree, { ISortedMapF } from "./tree/b+tree";
import compareKeys from "./util/cmp";
@ -1386,11 +1387,27 @@ export class MemoryBackend implements Backend {
);
}
let indexData = index.modifiedData || index.originalData;
const indexKeys = getIndexKeys(
value,
indexProperties.keyPath,
indexProperties.multiEntry,
);
let indexKeys;
try {
indexKeys = getIndexKeys(
value,
indexProperties.keyPath,
indexProperties.multiEntry,
);
} catch (e) {
if (e instanceof DataError) {
const n = index.modifiedName || index.originalName;
const p = JSON.stringify(indexProperties.keyPath);
const m = `Failed to extract index keys from index ${n} for keyPath ${p}.`;
if (this.enableTracing) {
console.error(m);
console.error("value was", value);
}
throw new DataError(m);
} else {
throw e;
}
}
for (const indexKey of indexKeys) {
const existingRecord = indexData.get(indexKey);
if (existingRecord) {

View File

@ -42,6 +42,7 @@ const messages = {
export class AbortError extends Error {
constructor(message = messages.AbortError) {
super();
Object.setPrototypeOf(this, ConstraintError.prototype);
this.name = "AbortError";
this.message = message;
}
@ -50,6 +51,7 @@ export class AbortError extends Error {
export class ConstraintError extends Error {
constructor(message = messages.ConstraintError) {
super();
Object.setPrototypeOf(this, ConstraintError.prototype);
this.name = "ConstraintError";
this.message = message;
}
@ -58,6 +60,7 @@ export class ConstraintError extends Error {
export class DataCloneError extends Error {
constructor(message = messages.DataCloneError) {
super();
Object.setPrototypeOf(this, DataCloneError.prototype);
this.name = "DataCloneError";
this.message = message;
}
@ -66,6 +69,7 @@ export class DataCloneError extends Error {
export class DataError extends Error {
constructor(message = messages.DataError) {
super();
Object.setPrototypeOf(this, DataError.prototype);
this.name = "DataError";
this.message = message;
}
@ -74,6 +78,7 @@ export class DataError extends Error {
export class InvalidAccessError extends Error {
constructor(message = messages.InvalidAccessError) {
super();
Object.setPrototypeOf(this, InvalidAccessError.prototype);
this.name = "InvalidAccessError";
this.message = message;
}
@ -82,6 +87,7 @@ export class InvalidAccessError extends Error {
export class InvalidStateError extends Error {
constructor(message = messages.InvalidStateError) {
super();
Object.setPrototypeOf(this, InvalidStateError.prototype);
this.name = "InvalidStateError";
this.message = message;
}
@ -90,6 +96,7 @@ export class InvalidStateError extends Error {
export class NotFoundError extends Error {
constructor(message = messages.NotFoundError) {
super();
Object.setPrototypeOf(this, NotFoundError.prototype);
this.name = "NotFoundError";
this.message = message;
}
@ -98,6 +105,7 @@ export class NotFoundError extends Error {
export class ReadOnlyError extends Error {
constructor(message = messages.ReadOnlyError) {
super();
Object.setPrototypeOf(this, ReadOnlyError.prototype);
this.name = "ReadOnlyError";
this.message = message;
}
@ -106,6 +114,7 @@ export class ReadOnlyError extends Error {
export class TransactionInactiveError extends Error {
constructor(message = messages.TransactionInactiveError) {
super();
Object.setPrototypeOf(this, TransactionInactiveError.prototype);
this.name = "TransactionInactiveError";
this.message = message;
}
@ -114,6 +123,7 @@ export class TransactionInactiveError extends Error {
export class VersionError extends Error {
constructor(message = messages.VersionError) {
super();
Object.setPrototypeOf(this, VersionError.prototype);
this.name = "VersionError";
this.message = message;
}