-
-
Notifications
You must be signed in to change notification settings - Fork 37.3k
Should Node.js standard library throw custom Error subclasses? #8342
Copy link
Copy link
Closed
Labels
errorsIssues and PRs related to JavaScript errors originating in Node.js core.Issues and PRs related to JavaScript errors originating in Node.js core.feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
Description
Activity
Metadata
Metadata
Assignees
Labels
errorsIssues and PRs related to JavaScript errors originating in Node.js core.Issues and PRs related to JavaScript errors originating in Node.js core.feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
As we know, ECMAScript define only few
Errorsubclasses. W3C specifications adds to this listDOMExceptionandURIError. Right now, Node.js implements sevenErrors:On other side we have Java standard library that defines 74 classes extending java.lang.Exception 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.
Therefore, I propose:
SystemError(class SystemError extends Error)FileSystemErrorandNetworkErrorto inherit fromSystemErrorDeprecationErrorinheriting fromErrrorfor deprecated featuresErrorin standard libraryDisadvantages:
err.constructor === TypeErrorcan breakAdvantages:
.catch(klass, handler)easier to useLoose ideas:
DatabaseErrorto be subclassed by database modulesI'm working on pull request to replace
new Errorwithnew TypeErrorornew RangeErrorwherever it makes sense.