Uncaught exception TypeError, Object.keys called on non-object
- Lingua principale
- JavaScript
- Stelle
- 2k
- Fork
- 238
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
I am trying to set up this module in my project using the nano-adapter. I am trying to save a document in this way:
```
Schema = require('jugglingdb').Schema
schema = new Schema 'nano', { ###config goes here### }
# creating model
User = schema.define 'User',
prop: String
# saving instance
user = User()
user.prop = "testing"
user.save (err, result) ->
console.log "Err", err
console.log "Res", result
```
it does save the document in the DB correctly but throws this exception:
```
error: Uncaught exception: __chain__=false, __wrapped__=[__chain__=false, name=TypeError, message=Object.keys called on non-object, stack=TypeError: Object.keys called on non-object
at Function.keys (native)
at Function.AbstractClass._fromDB (/myproject/node_modules/jugglingdb/lib/model.js:202:28)
at /myproject/node_modules/jugglingdb/lib/model.js:317:37
at /myproject/node_modules/jugglingdb-nano/lib/nano.js:105:16
at Request._callback (/myproject/node_modules/jugglingdb-nano/node_modules/nano/nano.js:288:11)
at Request.self.callback (/myproject/node_modules/jugglingdb-nano/node_modules/nano/node_modules/request/request.js:129:22)
at Request.EventEmitter.emit (events.js:98:17)
at Request. (/myproject/node_modules/jugglingdb-nano/node_modules/nano/node_modules/request/request.js:873:14)
at Request.EventEmitter.emit (events.js:117:20)
at IncomingMessage. (/myproject/node_modules/jugglingdb-nano/node_modules/nano/node_modules/request/request.js:824:12)]
```
I see that inside model.js(317) you have this:
```
if (rev) {
rev = Model._fromDB(rev);
obj._rev = rev
}
```
Model._fromDB implementation
```
AbstractClass._fromDB = function (data) {
if (!data) return;
var definition = this.schema.definitions[this.modelName].properties;
var propNames = Object.keys(data);
...
```
Obviously data in this case is the revision number which is a string not an object.
Am I missing something? Is this bug related to the nano-adapter?
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
The error occurs in node_modules/jugglingdb/lib/model.js at line 202 in AbstractClass._fromDB, where Object.keys is called on a string revision. Check the nano adapter at node_modules/jugglingdb-nano/lib/nano.js line 105 to see what data is passed. The fix likely involves handling the rev parameter in model.js line 317 to avoid calling _fromDB on a non-object. Run the provided code snippet to reproduce the error.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, node.js
- Ambito
- backend, databases
- Tipo di issue
- Bug
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 45/100