meteor / validated-method

Meteor methods with better scoping, argument checking, and good defaults.
https://atmospherejs.com/mdg/validated-method
MIT License
194 stars 28 forks source link

Throw error when one of the mixins doesn't return options object. #24

Closed johanbrook closed 8 years ago

johanbrook commented 8 years ago

Fixes #23.

@stubailo I'm throwing inside of the applyMixins function instantly if the mixin in the forEach callback isn't returning a plain object.

Error in methodWithFaultySchemaMixin method: The function 'nonReturningFunction' didn't return the options object

resp.

Error in methodWithFaultySchemaMixin method: One of the mixins didn't return the options object

  

stubailo commented 8 years ago

Hmm, this is making me think that all mixins should have a well-defined name property. Also, it's weird that the stack trace in this error will actually show the validated-method package, so in the worst case you'll get "One of the mixins didn't return an options object" and the trace will be from this package. I guess you will be able to use that to figure out which method it is.

Thoughts?

stubailo commented 8 years ago

I'm thinking at the least the error message should include the name of the ValidatedMethod in which the mixin was used, if such exists.

johanbrook commented 8 years ago

Hmm, this is making me think that all mixins should have a well-defined name property.

I hear you, but it might take the simplicity with "it's just functions" away.

I'm thinking at the least the error message should include the name of the ValidatedMethod in which the mixin was used, if such exists.

Yes, that's valid :) I'll fix.

At least the trace will point to the location where the ValidatedMethod was instantiated. And it might perhaps be possible to pass the mixin in question as a parameter to the Error thrown, as an extra data item?

stubailo commented 8 years ago

Nah I think you're right - for now just adding the name of the method will be fine.

johanbrook commented 8 years ago

@stubailo Pushed.

As you can see in the tests, the error messages are now:

Error in methodWithFaultySchemaMixin method: The function 'nonReturningFunction' didn't return the options object

resp.

Error in methodWithFaultySchemaMixin method: One of the mixins didn't return the options object
stubailo commented 8 years ago

Looks great!

johanbrook commented 8 years ago

:zap: :smile: