pouchdb: Uncaught TypeError: Cannot read property 'seq' of undefined

Issue

I’m running PouchDb in a node/express backend.

PouchDb is using websql to persist data to a SQLite database.

If I open the database in DB Browser for SQLite, I can make manual changes to documents in the PouchDb database. This has no impact on PouchDb.

But, if there is a pending change in the SQLite database, PouchDb takes down the node server.

 /node_modules/pouchdb-adapter-websql-core/lib/index.js:400
@serge/server:           var seq = res.rows.item(0).seq;
@serge/server:                                     ^
@serge/server: TypeError: Cannot read property 'seq' of undefined
@serge/server:     at SQLTask.sqlCallback (/node_modules/pouchdb-adapter-websql-core/lib/index.js:400:37)
@serge/server:     at /node_modules/websql/lib/websql/WebSQLTransaction.js:70:19
@serge/server:     at checkDone (/node_modules/websql/lib/sqlite/SQLiteDatabase.js:50:7)
@serge/server:     at /node_modules/websql/lib/sqlite/SQLiteDatabase.js:59:7
@serge/server:     at Statement.<anonymous> (/node_modules/websql/lib/sqlite/SQLiteDatabase.js:21:5)
@serge/server: error Command failed with exit code 1.
@serge/server: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Pending changes for a SQLite database called backend.sqlite introduce a journal rollback file called `backend.sqlite-journal’.

Info

  • Environment: Node.js
  • Platform: Chrome/Macos or Chrome/Windows
  • Adapter: WebSQL/
  • Server: Node

Reproduce

  • Create PouchDb database, with websql/sqlite backend
  • ‘put’ document to database
  • open database in DB Browser for SQLite
  • open document from by-sequence table
  • make minor change to document (still use valid JSON)
  • click on Apply, then Write Changes
  • put another document - works fine
  • make another change to document
  • click on Apply but NOT Write Changes
  • put another document - above error displayed, node exits

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 16 (8 by maintainers)

Most upvoted comments

Let me find some time to see if I can reproduce it and see what is broken and a suggested fix.

I’ll try to get to that in the next day or two if that works for you. 😃

On Jul 8, 2021, at 4:37 AM, Ian Mayo @.***> wrote:

Hello @seigel - I did fund a developer to investigate a fix to the PouchDb driver using the above repo, but his unfamiliarity with PouchDb codebase meant he was unable to identify the fix.

If you’re able to give pointers to where/how PouchDb could return an error code instead of exiting - then I’ll carry on trying to sponsor a fix. Alternatively, I’d be happy to discuss sponsoring you fixing it, via DM.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

Hello @seigel , sorry for the delay.

It would be too complex to pull out the code from my app. I’ve made a demonstrator for the issue here: https://github.com/serge-web/PouchDb_Demonstrator

screencast

More detailed video feed here

As the video shows: if there is a pending change in the database we get a 409 conflict status returned if we try to push a local document. But, node exits if we try to push a normal document. Ideally we’d get this 409 error instead of node exit.