{"action":"created","issue":{"url":"https://api.github.com/repos/nodejs/node/issues/5981","repository_url":"https://api.github.com/repos/nodejs/node","labels_url":"https://api.github.com/repos/nodejs/node/issues/5981/labels{/name}","comments_url":"https://api.github.com/repos/nodejs/node/issues/5981/comments","events_url":"https://api.github.com/repos/nodejs/node/issues/5981/events","html_url":"https://github.com/nodejs/node/pull/5981","id":145020163,"number":5981,"title":"net: improve socket.write() error message","user":{"login":"phillipj","id":1231635,"avatar_url":"https://avatars.githubusercontent.com/u/1231635?v=3","gravatar_id":"","url":"https://api.github.com/users/phillipj","html_url":"https://github.com/phillipj","followers_url":"https://api.github.com/users/phillipj/followers","following_url":"https://api.github.com/users/phillipj/following{/other_user}","gists_url":"https://api.github.com/users/phillipj/gists{/gist_id}","starred_url":"https://api.github.com/users/phillipj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phillipj/subscriptions","organizations_url":"https://api.github.com/users/phillipj/orgs","repos_url":"https://api.github.com/users/phillipj/repos","events_url":"https://api.github.com/users/phillipj/events{/privacy}","received_events_url":"https://api.github.com/users/phillipj/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/nodejs/node/labels/net","name":"net","color":"eb6420"},{"url":"https://api.github.com/repos/nodejs/node/labels/semver-major","name":"semver-major","color":"fbca04"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-03-31T21:13:29Z","updated_at":"2016-04-01T16:46:48Z","closed_at":"2016-04-01T16:46:48Z","pull_request":{"url":"https://api.github.com/repos/nodejs/node/pulls/5981","html_url":"https://github.com/nodejs/node/pull/5981","diff_url":"https://github.com/nodejs/node/pull/5981.diff","patch_url":"https://github.com/nodejs/node/pull/5981.patch"},"body":"### Pull Request check-list\r\n\r\n- [ ] Does `make -j8 test` (UNIX) or `vcbuild test nosign` (Windows) pass with\r\n  this change (including linting)?\r\n- [x] Is the commit message formatted according to [CONTRIBUTING.md][0]?\r\n- [x] If this change fixes a bug (or a performance problem), is a regression\r\n  test (or a benchmark) included?\r\n- [ ] Is a documentation update included (if this change modifies\r\n  existing APIs, or introduces new ones)?\r\n\r\n### Affected core subsystem(s)\r\n\r\nnet\r\n\r\n[0]: https://github.com/nodejs/node/blob/master/CONTRIBUTING.md#step-3-commit\r\n\r\n### Description of change\r\n\r\nInformative error messages are very important for developers and could possibly save hours of debugging and frustration. This improves the error message thrown when writing invalid data into a socket, by communicating what's expected compared to what the developer just tried to write.\r\n\r\nWhen passing anything other than a string or buffer to `socket.write()`, a TypeError with saying `Invalid data` gets thrown. E.g:\r\n\r\n```bash\r\nTypeError: Invalid data\r\n    at Socket.write (net.js:623:11)\r\n    at Socket.net.createConnection (/Users/phillipj/my-awesome-sock-script.js:5:12)\r\n    at Socket.g (events.js:271:16)\r\n    at emitNone (events.js:85:20)\r\n    at Socket.emit (events.js:179:7)\r\n```\r\n\r\nThis has bit me more than once as it doesn't really say much about what was expected or what I did wrong, other than some data being invalid.\r\n\r\nGetting something like this would be a lot more helpful:\r\n```bash\r\nTypeError: Invalid data, chunk must be a string or a buffer, not number\r\n    at Socket.write (net.js:623:11)\r\n    at Socket.net.createConnection (/Users/phillipj/my-awesome-sock-script.js:5:12)\r\n    at Socket.g (events.js:271:16)\r\n    at emitNone (events.js:85:20)\r\n    at Socket.emit (events.js:179:7)\r\n    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1048:10)```\r\n```"},"comment":{"url":"https://api.github.com/repos/nodejs/node/issues/comments/204467071","html_url":"https://github.com/nodejs/node/pull/5981#issuecomment-204467071","issue_url":"https://api.github.com/repos/nodejs/node/issues/5981","id":204467071,"user":{"login":"jasnell","id":439929,"avatar_url":"https://avatars.githubusercontent.com/u/439929?v=3","gravatar_id":"","url":"https://api.github.com/users/jasnell","html_url":"https://github.com/jasnell","followers_url":"https://api.github.com/users/jasnell/followers","following_url":"https://api.github.com/users/jasnell/following{/other_user}","gists_url":"https://api.github.com/users/jasnell/gists{/gist_id}","starred_url":"https://api.github.com/users/jasnell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasnell/subscriptions","organizations_url":"https://api.github.com/users/jasnell/orgs","repos_url":"https://api.github.com/users/jasnell/repos","events_url":"https://api.github.com/users/jasnell/events{/privacy}","received_events_url":"https://api.github.com/users/jasnell/received_events","type":"User","site_admin":false},"created_at":"2016-04-01T16:46:48Z","updated_at":"2016-04-01T16:46:48Z","body":"Landed in ec49fc8"}}