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", "name": "idb-bridge",
"version": "0.0.11", "version": "0.0.12",
"description": "IndexedDB implementation that uses SQLite3 as storage", "description": "IndexedDB implementation that uses SQLite3 as storage",
"main": "./build/index.js", "main": "./build/index.js",
"types": "./build/index.d.ts", "types": "./build/index.d.ts",

View File

@ -32,6 +32,7 @@ import {
InvalidStateError, InvalidStateError,
InvalidAccessError, InvalidAccessError,
ConstraintError, ConstraintError,
DataError,
} from "./util/errors"; } from "./util/errors";
import BTree, { ISortedMapF } from "./tree/b+tree"; import BTree, { ISortedMapF } from "./tree/b+tree";
import compareKeys from "./util/cmp"; import compareKeys from "./util/cmp";
@ -1386,11 +1387,27 @@ export class MemoryBackend implements Backend {
); );
} }
let indexData = index.modifiedData || index.originalData; let indexData = index.modifiedData || index.originalData;
const indexKeys = getIndexKeys( let indexKeys;
value, try {
indexProperties.keyPath, indexKeys = getIndexKeys(
indexProperties.multiEntry, 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) { for (const indexKey of indexKeys) {
const existingRecord = indexData.get(indexKey); const existingRecord = indexData.get(indexKey);
if (existingRecord) { if (existingRecord) {

View File

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