geddy / model

Datastore-agnostic ORM in JavaScript
265 stars 55 forks source link

Error message better when trying to use an invalid model prop. #168

Closed JohnPostlethwait closed 10 years ago

JohnPostlethwait commented 10 years ago

When using an invalid property while querying the model, like so:

geddy.model.MyModel.all({ bad_prop: 'some_value' }, function () {
// ...
});

Geddy model would throw this exception:

TypeError: Cannot read property 'datatype' of undefined
at _createComparison
(/usr/local/lib/node_modules/geddy/node_modules/model/lib/query/query.js:232:27) at _createOperation
(/usr/local/lib/node_modules/geddy/node_modules/model/lib/query/query.js:175:43) at Query.initialize
(/usr/local/lib/node_modules/geddy/node_modules/model/lib/query/query.js:345:40) at Query
(/usr/local/lib/node_modules/geddy/node_modules/model/lib/query/query.js:12:19) at Function.obj.all
(/usr/local/lib/node_modules/geddy/node_modules/model/lib/index.js:378:15) at show
(/Users/my_username/src/my_app/app/controllers/my_controller.js:12:26) at callback
(/usr/local/lib/node_modules/geddy/lib/controller/base_controller.js:282:22) at controller.BaseController._handleAction
(/usr/local/lib/node_modules/geddy/lib/controller/base_controller.js:295:7) at cb [as callback]
(/usr/local/lib/node_modules/geddy/lib/app/index.js:258:36) at async.Initializer.complete
(/usr/local/lib/node_modules/geddy/node_modules/utilities/lib/async.js:286:10)

This is pretty unhelpful. I have changed the error to be more informative to the end-user:

Error: The property "bad_prop" is not a valid property on the
MyModel model. at _createComparison
mde commented 10 years ago

This is awesome. Would it be possible to get a test for this?

JohnPostlethwait commented 10 years ago

I was having some node-gyp install issues on OSX 10.8.5 when trying to install the dependencies. I'll see if I can get that sorted out and get the tests running in order to write one...

JohnPostlethwait commented 10 years ago

Unit test added.

JohnPostlethwait commented 10 years ago

Is that failure unrelated?

mde commented 10 years ago

It's unrelated. It's an impossible-to-repro problem that happens sporadically in the Postgres adapter.

mde commented 10 years ago

Oh, your unit test is even better. Nice work, thanks.

JohnPostlethwait commented 10 years ago

Sure!