Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to output more info when "Assertion Failed"? #1777

Open
paulrosen opened this issue Aug 3, 2023 · 7 comments
Open

Is it possible to output more info when "Assertion Failed"? #1777

paulrosen opened this issue Aug 3, 2023 · 7 comments

Comments

@paulrosen
Copy link

I'm trying to hook up my dexie db to the cloud and got a bunch of promising output in the console, but then I started getting assertion errors. I have no info about what to look for. Here is the entirety of the message:

Failed to sync client changes Error: Assertion Failed
    at assert (utils.ts:71:19)
    at Dexie$1.setByKeyPath (utils.ts:138:9)
    at encodeIdsForServer.ts:38:19
    at Array.forEach (<anonymous>)
    at encodeIdsForServer.ts:29:16
    at Array.forEach (<anonymous>)
    at encodeIdsForServer (encodeIdsForServer.ts:25:10)
    at syncWithServer.ts:51:14
    at Generator.next (<anonymous>)
    at fulfilled (tslib.es6.js:73:58)

On the console before that I got lines starting with
SYNC STARTED
syncIfPossible
Sync request
BroadcastedAndLocalEvent
etc...
MORE SYNC NEEDED
SYNC STARTED
New Websocket Connection
dexie-cloud WebSocket create
Error from _sync (with the same assertion error)

How do I begin to debug this?

@paulrosen
Copy link
Author

One thing that would give me a little clue is if I could see what is stored on the cloud for my account. Is there a way to dump that out? Or is the a "Dashboard" website I could log into? If the problem were data-related I can try to remove that record and see if the rest works.

I'll try to delete my indexedDB and put records in one at a time and see if I get a pattern. I don't have time today for that, though.

@dfahlander
Copy link
Collaborator

dfahlander commented Aug 3, 2023

Thanks for the log printouts - seems as the problem is related a table with compound primary keys but the keys are not arrays as expected but plain strings. This could indicate a bug in dexie-cloud. I'll see if I can reproduce the issue from your database if I get a chance tomorrow. You can export everything to a JSON file if that would help using npx dexie-cloud@latest export. Compound primary keys are stored as JSON strings and it might be a problem with that. I might get wiser after looking into your db.

An admin dashboard with database and subscription management is under development as the last part before the service goes into production in the end of the summer. For now, it's only npx dexie-cloud export and the REST API available to inspect what's stored in the cloud.

@paulrosen
Copy link
Author

all-data.txt

That is what export gives me - but did you want the contents of indexedDB instead? That is much larger.

@paulrosen
Copy link
Author

Here's the initialization:

class SetListDb extends Dexie {
	public metaNames: Dexie.Table<MetaNames, number>;
	public tunes: Dexie.Table<Tune, number>;
	public lists: Dexie.Table<List, number>;
	public tunesInLists: Dexie.Table<TuneInList, [number, number, number]>;
	constructor(name: string, options?: any) {
		super(name, options);
		this.version(2).stores({
			tunes: '@id, name, abc, leader, roadMap, countOff, key, bpm',
			lists: '@id, name',
			tunesInLists: '[tuneId+listId+order],tuneId,listId,order',
			metaNames: '@id, tabTitle'
		});
		this.metaNames = this.table('metaNames');
		this.tunes = this.table('tunes');
		this.lists = this.table('lists');
		this.tunesInLists = this.table('tunesInLists');
	}
}

And the model:

export class MetaNames {
	tabTitle: string;
    constructor(name:string) {}
}

export class Tune {
    id:number;
    name: string;
	abc: string;
	leader: string;
	roadMap: string;
	countOff: string;
	key: string;
	tempo: string;
    lists: List[];
	order?: number;
    constructor(name:string) {this.name = name}
}

export class List {
    id:number;
    name: string;
    tunes:Tune[];
    constructor(name:string) {this.name=name}
}

export class TuneInList {
	id?: number;
	tuneId: number;
	listId: number;
	order: number;
	constructor() {}
}

@paulrosen
Copy link
Author

A little more info:

I split the writes into sections and I successfully wrote all the MetaNames, Tunes, and Lists. That synced up properly.

But when I went to write TuneInList it started failing. That is doing a many-to-many relationship.

dfahlander added a commit that referenced this issue Aug 5, 2023
@dfahlander
Copy link
Collaborator

dfahlander commented Aug 5, 2023

I found the issue and it's really a bug occurring when client is about to sync a table with inbound compound keys. I've released a new version with "test" tag for you to try out:

npm i dexie-cloud-addon@4.0.1-beta.46

Let me know if this fixes it.

Another thing I noticed is that the typings for IDs in your code are all numbers while they really should be strings ('@'-keys) and the relation table should be:

export class TuneInList {
        //id?: number; not there!
	tuneId: string; // not number
	listId: string; // not number
	order: number;
	constructor() {}
}

Please try out the fix and let me know if everything is working properly with it.

@paulrosen
Copy link
Author

Yes! can confirm - it works. And I ran npx dexie-cloud@latest export all-data.json and all the data is there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants