1602 / 1602/jugglingdb

Uncaught exception TypeError, Object.keys called on non-object

Offen
#392 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
JavaScript
Sterne
2k
Forks
238
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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?

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, node.js
Bereich
backend, databases
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.