{"action":"created","issue":{"url":"https://api.github.com/repos/nodejs/node/issues/8342","repository_url":"https://api.github.com/repos/nodejs/node","labels_url":"https://api.github.com/repos/nodejs/node/issues/8342/labels{/name}","comments_url":"https://api.github.com/repos/nodejs/node/issues/8342/comments","events_url":"https://api.github.com/repos/nodejs/node/issues/8342/events","html_url":"https://github.com/nodejs/node/issues/8342","id":174079400,"number":8342,"title":"Should Node.js standard library throw custom Error subclasses?","user":{"login":"Ginden","id":3824055,"avatar_url":"https://avatars.githubusercontent.com/u/3824055?v=3","gravatar_id":"","url":"https://api.github.com/users/Ginden","html_url":"https://github.com/Ginden","followers_url":"https://api.github.com/users/Ginden/followers","following_url":"https://api.github.com/users/Ginden/following{/other_user}","gists_url":"https://api.github.com/users/Ginden/gists{/gist_id}","starred_url":"https://api.github.com/users/Ginden/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ginden/subscriptions","organizations_url":"https://api.github.com/users/Ginden/orgs","repos_url":"https://api.github.com/users/Ginden/repos","events_url":"https://api.github.com/users/Ginden/events{/privacy}","received_events_url":"https://api.github.com/users/Ginden/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/nodejs/node/labels/error-handling","name":"error-handling","color":"e11d21"},{"url":"https://api.github.com/repos/nodejs/node/labels/feature%20request","name":"feature request","color":"0D7BDE"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-08-30T17:35:35Z","updated_at":"2016-08-30T18:12:33Z","closed_at":null,"body":"As we know, ECMAScript define only few `Error` subclasses. W3C specifications adds to this list `DOMException` and `URIError`. Right now, Node.js implements seven `Errors`:\r\n\r\n* Error\r\n* EvalError\r\n* RangeError\r\n* ReferenceError\r\n* SyntaxError\r\n* TypeError\r\n* URIError\r\n\r\nOn other side we have Java standard library that defines 74 classes extending [java.lang.Exception](https://docs.oracle.com/javase/7/docs/api/java/lang/Exception.html) and numerous other extending these subclasses. Most of them doesn't make sense in Node.js context, as our standard library is much smaller, but I'm convinced that 7 errors defined in ECMAScript are too general to provide meaningful information on types of error that can happen.\r\n\r\nTherefore, I propose:\r\n\r\n* make all exceptions coming from syscalls inherit from new class `SystemError` (`class SystemError extends Error`)\r\n** create classes like `FileSystemError` and `NetworkError` to inherit from `SystemError`\r\n* add class `DeprecationError` inheriting from `Errror` for deprecated features\r\n* discourage creating direct instances of `Error` in standard library\r\n\r\nDisadvantages:\r\n\r\n* code directly checking `err.constructor === TypeError` can break\r\n\r\nAdvantages:\r\n\r\n* better typing for TypeScript\r\n** many IDEs can use TypeScript definition files and use them as ad-hoc documentation, even if you write in JavaScript\r\n* Bluebird [`.catch(klass, handler)`](http://bluebirdjs.com/docs/api/catch.html) easier to use\r\n\r\nIdeas:\r\n\r\n* export classes like `DatabaseError` to be subclassed by database modules\r\n\r\nI'm working on pull request to replace `new Error` with `new TypeError` or `new RangeError` wherever it makes sense."},"comment":{"url":"https://api.github.com/repos/nodejs/node/issues/comments/243529504","html_url":"https://github.com/nodejs/node/issues/8342#issuecomment-243529504","issue_url":"https://api.github.com/repos/nodejs/node/issues/8342","id":243529504,"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-08-30T18:12:33Z","updated_at":"2016-08-30T18:12:33Z","body":"Related to this is my PR https://github.com/nodejs/node/pull/6573, which begins attaching a stable error code to every error. I need to get through and get that PR rebased and updated but it should give an idea on the direction."}}
{"actor":{"display_login":"jasnell"}}