質問

I am building up a webapp with offline functionality. I am using combination of webcache and pouchDB to achieve it.

Currently I am testing recovery mechanisms against DB corruption. My premise is that since pouchDB is running in client, it is exposed to anyone who by mistake or on purpose can corrupt the DB. Also maybe in case of bugs or similar, DB could get corrupted. Then, if DB gets corrupted, unless it gets detected and clean by webapp, this will never work correctly.

Test is quite simple: - Create PouchDB:

    var dbOptions = {
       auto_compaction : false,
       cache : false
    };
    var db = new PouchDB('myDB',dbOptions);

  • With Developer Tools delete part of the database.
  • On loading the application it tries to read all documents:
    db.allDocs({include_docs : true}, function(_err,_response){
        (certain code here)
    }

It is at this point when "Uncaught TypeError: Cannot set property '_rev' of undefined " is thrown. I tried to catch exception and using provided promise by pouchDB but none did work.

Did any of you fellows have similar problem? How did you solve it?

EDIT: When PouchDB returns 500 Internal error, how is the application supposed to recover from it? I tried to destroy the database

    db.destroy(function(err,info){console.log(err||info);}

but it does not work. It returns 500 Internal error as well.

役に立ちましたか?

解決

It indeed sounds like your database got corrupted. Sorry about that; we try to write bulletproof code, but since we're working against the WebSQL/IndexedDB APIs, there's always the possibility that something goes wrong at that interface, the browser crashes, lightning strikes your computer, etc.

500 errors indicate an internal PouchDB error, so you're not supposed to recover from them. Probably the best way to protect against corruption like that is just to set up continual sync with a CouchDB server (kind of the point of PouchDB anyway). CouchDB is a full database implemented from top to bottom and is very robust – since it uses append-only database files, your database can never get corrupted. So if you use continuous sync, you can always delete the PouchDB database and recover from CouchDB.

That being said, if you could let us know which version of PouchDB you're running, which browser you saw this on, or even a code snippet to reproduce, that would be really helpful. If you're using Firefox, you can also send us the storage files themselves for IDB by following the instructions here to find the Profile folder and then sending us the contents of the storage/persistent/<my_site>/idb folder. Thanks!

他のヒント

I got this error while adding a new schema to my RxDB database. It turned out I included the primary key and wrong property names into encrypted fields. I removed the primary key and put proper names and it worked fine after that.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top