Don't allow non-functions to be set as getters or setters #704

ljharb opened this Issue Feb 1, 2012 · 4 comments


None yet

2 participants

ljharb commented Feb 1, 2012

I misread the documentation and passed "true" for "get" when creating a schema. This led to an error in the save callback: [TypeError: Object true has no method 'call']

Obviously I'm the one who messed up, but it would be nice if it failed much faster. Attempting to create a schema with a getter or setter that's not a function should either cause an error, be ignored, and/or console.log a warning - it would have saved me hours of troubleshooting.

I'd do the pull request myself but I'm not sure where that check should be added. If somebody can point me to the file/function/line, I'll be happy to make the change.

fredrick commented Feb 1, 2012

The relevant lines are in the SchemaType prototype,

Something along the lines of typeof(fn) === 'function' would probably suffice, however, not sure if this appropriate, and what the thoughts of the principle maintainers on this kind of defensive argument/type checking. Comments?

ljharb commented Feb 1, 2012

Since "required" forces any !== false value to be true, I'm going to go with "force a sensible value". Pull request in #706

ljharb commented Feb 1, 2012

Fixing typos and throwing an Error instead in #707

ljharb commented Feb 2, 2012

Pull request's merged, thanks!

@ljharb ljharb closed this Feb 2, 2012
@gitfy gitfy pushed a commit to gitfy/mongoose that referenced this issue Feb 5, 2012
@aheckmann aheckmann ocd + test
closes #707
closes #704
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment