{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/2832","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/2832/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/2832/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/2832/events","html_url":"https://github.com/Automattic/mongoose/issues/2832","id":65887358,"number":2832,"title":"Mongoose 4.0.1 - Exception inside of a setter function causes ValidationError with undefined path","user":{"login":"lbeschastny","id":1128370,"avatar_url":"https://avatars.githubusercontent.com/u/1128370?v=3","gravatar_id":"","url":"https://api.github.com/users/lbeschastny","html_url":"https://github.com/lbeschastny","followers_url":"https://api.github.com/users/lbeschastny/followers","following_url":"https://api.github.com/users/lbeschastny/following{/other_user}","gists_url":"https://api.github.com/users/lbeschastny/gists{/gist_id}","starred_url":"https://api.github.com/users/lbeschastny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lbeschastny/subscriptions","organizations_url":"https://api.github.com/users/lbeschastny/orgs","repos_url":"https://api.github.com/users/lbeschastny/repos","events_url":"https://api.github.com/users/lbeschastny/events{/privacy}","received_events_url":"https://api.github.com/users/lbeschastny/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Automattic/mongoose/labels/fixed?","name":"fixed?","color":"0052cc"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/Automattic/mongoose/milestones/36","html_url":"https://github.com/Automattic/mongoose/milestones/4.0.2","labels_url":"https://api.github.com/repos/Automattic/mongoose/milestones/36/labels","id":1043141,"number":36,"title":"4.0.2","description":"","creator":{"login":"vkarpov15","id":1620265,"avatar_url":"https://avatars.githubusercontent.com/u/1620265?v=3","gravatar_id":"","url":"https://api.github.com/users/vkarpov15","html_url":"https://github.com/vkarpov15","followers_url":"https://api.github.com/users/vkarpov15/followers","following_url":"https://api.github.com/users/vkarpov15/following{/other_user}","gists_url":"https://api.github.com/users/vkarpov15/gists{/gist_id}","starred_url":"https://api.github.com/users/vkarpov15/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vkarpov15/subscriptions","organizations_url":"https://api.github.com/users/vkarpov15/orgs","repos_url":"https://api.github.com/users/vkarpov15/repos","events_url":"https://api.github.com/users/vkarpov15/events{/privacy}","received_events_url":"https://api.github.com/users/vkarpov15/received_events","type":"User","site_admin":false},"open_issues":11,"closed_issues":10,"state":"open","created_at":"2015-03-28T20:52:22Z","updated_at":"2015-04-10T16:55:48Z","due_on":"2015-04-24T04:00:00Z","closed_at":null},"comments":3,"created_at":"2015-04-02T09:25:40Z","updated_at":"2015-04-10T19:46:53Z","closed_at":null,"body":"Hi.\r\n\r\nConsider the following code sample:\r\n\r\n```js\r\nvar mongoose = require('mongoose');\r\n\r\nmongoose.connect('mongodb://localhost/test');\r\n\r\nvar FooSchema = new mongoose.Schema({\r\n  data: {\r\n    type: String,\r\n    set: function (arr) {\r\n      throw new Error('Ooops!');\r\n    }\r\n  }\r\n});\r\n\r\nvar Foo = mongoose.model('Foo', FooSchema);\r\n\r\nFoo.create({\r\n  data: undefined\r\n}, function (err, doc) {\r\n  console.error(err);\r\n})\r\n```\r\n\r\nThis code throws the following `ValidationError` exception:\r\n\r\n```\r\n{ [ValidationError: Foo validation failed]\r\n  message: 'Foo validation failed',\r\n  name: 'ValidationError',\r\n  errors: \r\n   { undefined: \r\n      { [CastError: Cast to String failed for value \"undefined\" at path \"undefined\"]\r\n        message: 'Cast to String failed for value \"undefined\" at path \"undefined\"',\r\n        name: 'CastError',\r\n        kind: 'String',\r\n        value: undefined,\r\n        path: undefined } } }\r\n```\r\n\r\nAs you can see, it indicates `CastError` at `undefined` patch, instead of pointing me to the troublesome `data` path.\r\n\r\nThis thing made it really hard to find out that my code broke because of #1892 breaking change.\r\n"},"comment":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/comments/91663089","html_url":"https://github.com/Automattic/mongoose/issues/2832#issuecomment-91663089","issue_url":"https://api.github.com/repos/Automattic/mongoose/issues/2832","id":91663089,"user":{"login":"vkarpov15","id":1620265,"avatar_url":"https://avatars.githubusercontent.com/u/1620265?v=3","gravatar_id":"","url":"https://api.github.com/users/vkarpov15","html_url":"https://github.com/vkarpov15","followers_url":"https://api.github.com/users/vkarpov15/followers","following_url":"https://api.github.com/users/vkarpov15/following{/other_user}","gists_url":"https://api.github.com/users/vkarpov15/gists{/gist_id}","starred_url":"https://api.github.com/users/vkarpov15/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vkarpov15/subscriptions","organizations_url":"https://api.github.com/users/vkarpov15/orgs","repos_url":"https://api.github.com/users/vkarpov15/repos","events_url":"https://api.github.com/users/vkarpov15/events{/privacy}","received_events_url":"https://api.github.com/users/vkarpov15/received_events","type":"User","site_admin":false},"created_at":"2015-04-10T19:46:53Z","updated_at":"2015-04-10T19:46:53Z","body":"I'm gonna review #2862 again tomorrow - if you can double check that branch and see if it works for your use case that would be very helpful :)"}}