{"action":"created","comment":{"url":"https://api.github.com/repos/nodejs/node/pulls/comments/62552387","id":62552387,"diff_hunk":"@@ -0,0 +1,258 @@\n+'use strict';\n+\n+// The whole point behind this internal module is to allow Node.js to no\n+// longer be forced to treat every error message change as a semver-major\n+// change. The NodeError classes here all expose a `code` property whose\n+// value identifies the error.\n+\n+const kCode = Symbol('code');\n+\n+class NodeError extends Error {\n+  constructor(key, ...args) {\n+    super(message(key, args));\n+    this[kCode] = key;\n+    Error.captureStackTrace(this, NodeError);\n+  }\n+\n+  get name() {\n+    return `Error[${this[kCode]}]`;\n+  }\n+\n+  get code() {\n+    return this[kCode];\n+  }\n+}\n+\n+class NodeTypeError extends TypeError {\n+  constructor(key, ...args) {\n+    super(message(key, args));\n+    this[kCode] = key;\n+    Error.captureStackTrace(this, NodeTypeError);\n+  }\n+\n+  get name() {\n+    return `TypeError[${this[kCode]}]`;\n+  }\n+\n+  get code() {\n+    return this[kCode];\n+  }\n+}\n+\n+class NodeRangeError extends RangeError {\n+  constructor(key, ... args) {\n+    super(message(key, args));\n+    this[kCode] = key;\n+    Error.captureStackTrace(this, NodeRangeError);\n+  }\n+\n+  get name() {\n+    return `RangeError[${this[kCode]}]`;\n+  }\n+\n+  get code() {\n+    return this[kCode];\n+  }\n+}\n+\n+module.exports.Error = NodeError;\n+module.exports.TypeError = NodeTypeError;\n+module.exports.RangeError = NodeRangeError;\n+\n+var assert, util;\n+function lazyAssert() {\n+  if (!assert)\n+    assert = require('assert');\n+  return assert;\n+}\n+\n+function lazyUtil() {\n+  if (!util)\n+    util = require('util');\n+  return util;\n+}\n+\n+function message(key, args) {\n+  const assert = lazyAssert();\n+  const util = lazyUtil();\n+  const msg = Error[Symbol.for(key)];\n+  // We want to assert here because if this happens,\n+  // Node.js is doing something incorrect.\n+  assert(msg, `An invalid error message key was used: ${key}.`);\n+  let fmt = util.format;\n+  if (typeof msg === 'function') {\n+    fmt = msg;\n+  } else {\n+    args.unshift(msg);\n+  }\n+  const res = fmt.apply(null, args);\n+  // We want to assert here because if this happens,\n+  // Node.js is doing something incorrect.\n+  assert(res, 'An invalid formatted error message was returned.');\n+  return res;\n+}\n+\n+// Below is the catalog of messages\n+// Error keys should be all caps, value can\n+// be a string formatted for use with\n+// util.format, or a function.\n+\n+// Utility function for registering the error codes.\n+function E(sym, val) {","path":"lib/internal/errors.js","position":101,"original_position":101,"commit_id":"76bc6e617dd5a5934d6e14aa1c62286dcdd954fe","original_commit_id":"76bc6e617dd5a5934d6e14aa1c62286dcdd954fe","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},"body":"It could but doubt there'd be significant value in doing so. This is only used within this one module where we can easily ensure that the symbol values are always caps.","created_at":"2016-05-09T18:52:16Z","updated_at":"2016-05-09T18:52:16Z","html_url":"https://github.com/nodejs/node/pull/6573#discussion_r62552387","pull_request_url":"https://api.github.com/repos/nodejs/node/pulls/6573","_links":{"self":{"href":"https://api.github.com/repos/nodejs/node/pulls/comments/62552387"},"html":{"href":"https://github.com/nodejs/node/pull/6573#discussion_r62552387"},"pull_request":{"href":"https://api.github.com/repos/nodejs/node/pulls/6573"}}},"pull_request":{"url":"https://api.github.com/repos/nodejs/node/pulls/6573","id":68902566,"html_url":"https://github.com/nodejs/node/pull/6573","diff_url":"https://github.com/nodejs/node/pull/6573.diff","patch_url":"https://github.com/nodejs/node/pull/6573.patch","issue_url":"https://api.github.com/repos/nodejs/node/issues/6573","number":6573,"state":"open","locked":false,"title":"errors: add internal/errors module","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},"body":"##### Checklist\r\n\r\n- [x] tests and code linting passes\r\n- [x] a test and/or benchmark is included\r\n- [ ] documentation is changed or added\r\n- [x] the commit message follows commit guidelines\r\n\r\n##### Affected core subsystem(s)\r\n\r\nerrors (new subsystem)\r\n\r\n##### Description of change\r\n\r\n*Note: This is a **work in progress**. I am opening the PR to begin the discussion about the overall design. I will be iterating based on the feedback. This is far from being ready to land in it's current state.*\r\n\r\nThis is *step one* to making it so that *changes to error messages are not forced to be semver-major changes* any more. The internal errors.js module exports three custom error class instances that use an assigned static error code to look up the error message. The message itself can change but the error code would remain the same. Changes to error code would still be considered semver-major, but changes to the messages themselves would not be.\r\n\r\nThis also updates the Error objects created in lib/internal to use the new mechanism, changing and streamlining several of the error messages in the process. Obviously, this is a semver-major change on it's own.\r\n\r\nSeveral test cases were also modified and a new common.throws method added to test/common.js that understands the new code mechanism. This is added common.js so that the existing assert module api is unchanged.\r\n\r\n","created_at":"2016-05-04T17:43:27Z","updated_at":"2016-05-09T18:52:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"43a93966d784bb3039f631af05b02176517cfb1c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/nodejs/node/pulls/6573/commits","review_comments_url":"https://api.github.com/repos/nodejs/node/pulls/6573/comments","review_comment_url":"https://api.github.com/repos/nodejs/node/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nodejs/node/issues/6573/comments","statuses_url":"https://api.github.com/repos/nodejs/node/statuses/76bc6e617dd5a5934d6e14aa1c62286dcdd954fe","head":{"label":"jasnell:no-major-errors","ref":"no-major-errors","sha":"76bc6e617dd5a5934d6e14aa1c62286dcdd954fe","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},"repo":{"id":37868459,"name":"node","full_name":"jasnell/node","owner":{"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},"private":false,"html_url":"https://github.com/jasnell/node","description":"Future Node.js releases will be based on io.js","fork":true,"url":"https://api.github.com/repos/jasnell/node","forks_url":"https://api.github.com/repos/jasnell/node/forks","keys_url":"https://api.github.com/repos/jasnell/node/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jasnell/node/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jasnell/node/teams","hooks_url":"https://api.github.com/repos/jasnell/node/hooks","issue_events_url":"https://api.github.com/repos/jasnell/node/issues/events{/number}","events_url":"https://api.github.com/repos/jasnell/node/events","assignees_url":"https://api.github.com/repos/jasnell/node/assignees{/user}","branches_url":"https://api.github.com/repos/jasnell/node/branches{/branch}","tags_url":"https://api.github.com/repos/jasnell/node/tags","blobs_url":"https://api.github.com/repos/jasnell/node/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jasnell/node/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jasnell/node/git/refs{/sha}","trees_url":"https://api.github.com/repos/jasnell/node/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jasnell/node/statuses/{sha}","languages_url":"https://api.github.com/repos/jasnell/node/languages","stargazers_url":"https://api.github.com/repos/jasnell/node/stargazers","contributors_url":"https://api.github.com/repos/jasnell/node/contributors","subscribers_url":"https://api.github.com/repos/jasnell/node/subscribers","subscription_url":"https://api.github.com/repos/jasnell/node/subscription","commits_url":"https://api.github.com/repos/jasnell/node/commits{/sha}","git_commits_url":"https://api.github.com/repos/jasnell/node/git/commits{/sha}","comments_url":"https://api.github.com/repos/jasnell/node/comments{/number}","issue_comment_url":"https://api.github.com/repos/jasnell/node/issues/comments{/number}","contents_url":"https://api.github.com/repos/jasnell/node/contents/{+path}","compare_url":"https://api.github.com/repos/jasnell/node/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jasnell/node/merges","archive_url":"https://api.github.com/repos/jasnell/node/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jasnell/node/downloads","issues_url":"https://api.github.com/repos/jasnell/node/issues{/number}","pulls_url":"https://api.github.com/repos/jasnell/node/pulls{/number}","milestones_url":"https://api.github.com/repos/jasnell/node/milestones{/number}","notifications_url":"https://api.github.com/repos/jasnell/node/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jasnell/node/labels{/name}","releases_url":"https://api.github.com/repos/jasnell/node/releases{/id}","deployments_url":"https://api.github.com/repos/jasnell/node/deployments","created_at":"2015-06-22T17:01:18Z","updated_at":"2016-01-11T18:47:43Z","pushed_at":"2016-05-09T17:47:43Z","git_url":"git://github.com/jasnell/node.git","ssh_url":"git@github.com:jasnell/node.git","clone_url":"https://github.com/jasnell/node.git","svn_url":"https://github.com/jasnell/node","homepage":"https://iojs.org","size":194359,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":1,"forks":3,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"nodejs:master","ref":"master","sha":"9daf4a29378b6bdb4ce9b2c7ba32603f6a175d08","user":{"login":"nodejs","id":9950313,"avatar_url":"https://avatars.githubusercontent.com/u/9950313?v=3","gravatar_id":"","url":"https://api.github.com/users/nodejs","html_url":"https://github.com/nodejs","followers_url":"https://api.github.com/users/nodejs/followers","following_url":"https://api.github.com/users/nodejs/following{/other_user}","gists_url":"https://api.github.com/users/nodejs/gists{/gist_id}","starred_url":"https://api.github.com/users/nodejs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodejs/subscriptions","organizations_url":"https://api.github.com/users/nodejs/orgs","repos_url":"https://api.github.com/users/nodejs/repos","events_url":"https://api.github.com/users/nodejs/events{/privacy}","received_events_url":"https://api.github.com/users/nodejs/received_events","type":"Organization","site_admin":false},"repo":{"id":27193779,"name":"node","full_name":"nodejs/node","owner":{"login":"nodejs","id":9950313,"avatar_url":"https://avatars.githubusercontent.com/u/9950313?v=3","gravatar_id":"","url":"https://api.github.com/users/nodejs","html_url":"https://github.com/nodejs","followers_url":"https://api.github.com/users/nodejs/followers","following_url":"https://api.github.com/users/nodejs/following{/other_user}","gists_url":"https://api.github.com/users/nodejs/gists{/gist_id}","starred_url":"https://api.github.com/users/nodejs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodejs/subscriptions","organizations_url":"https://api.github.com/users/nodejs/orgs","repos_url":"https://api.github.com/users/nodejs/repos","events_url":"https://api.github.com/users/nodejs/events{/privacy}","received_events_url":"https://api.github.com/users/nodejs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nodejs/node","description":"Node.js JavaScript runtime :sparkles::turtle::rocket::sparkles:","fork":false,"url":"https://api.github.com/repos/nodejs/node","forks_url":"https://api.github.com/repos/nodejs/node/forks","keys_url":"https://api.github.com/repos/nodejs/node/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nodejs/node/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nodejs/node/teams","hooks_url":"https://api.github.com/repos/nodejs/node/hooks","issue_events_url":"https://api.github.com/repos/nodejs/node/issues/events{/number}","events_url":"https://api.github.com/repos/nodejs/node/events","assignees_url":"https://api.github.com/repos/nodejs/node/assignees{/user}","branches_url":"https://api.github.com/repos/nodejs/node/branches{/branch}","tags_url":"https://api.github.com/repos/nodejs/node/tags","blobs_url":"https://api.github.com/repos/nodejs/node/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nodejs/node/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nodejs/node/git/refs{/sha}","trees_url":"https://api.github.com/repos/nodejs/node/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nodejs/node/statuses/{sha}","languages_url":"https://api.github.com/repos/nodejs/node/languages","stargazers_url":"https://api.github.com/repos/nodejs/node/stargazers","contributors_url":"https://api.github.com/repos/nodejs/node/contributors","subscribers_url":"https://api.github.com/repos/nodejs/node/subscribers","subscription_url":"https://api.github.com/repos/nodejs/node/subscription","commits_url":"https://api.github.com/repos/nodejs/node/commits{/sha}","git_commits_url":"https://api.github.com/repos/nodejs/node/git/commits{/sha}","comments_url":"https://api.github.com/repos/nodejs/node/comments{/number}","issue_comment_url":"https://api.github.com/repos/nodejs/node/issues/comments{/number}","contents_url":"https://api.github.com/repos/nodejs/node/contents/{+path}","compare_url":"https://api.github.com/repos/nodejs/node/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nodejs/node/merges","archive_url":"https://api.github.com/repos/nodejs/node/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nodejs/node/downloads","issues_url":"https://api.github.com/repos/nodejs/node/issues{/number}","pulls_url":"https://api.github.com/repos/nodejs/node/pulls{/number}","milestones_url":"https://api.github.com/repos/nodejs/node/milestones{/number}","notifications_url":"https://api.github.com/repos/nodejs/node/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nodejs/node/labels{/name}","releases_url":"https://api.github.com/repos/nodejs/node/releases{/id}","deployments_url":"https://api.github.com/repos/nodejs/node/deployments","created_at":"2014-11-26T19:57:11Z","updated_at":"2016-05-09T18:35:51Z","pushed_at":"2016-05-09T18:05:04Z","git_url":"git://github.com/nodejs/node.git","ssh_url":"git@github.com:nodejs/node.git","clone_url":"https://github.com/nodejs/node.git","svn_url":"https://github.com/nodejs/node","homepage":"https://nodejs.org","size":256963,"stargazers_count":22975,"watchers_count":22975,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3221,"mirror_url":null,"open_issues_count":657,"forks":3221,"open_issues":657,"watchers":22975,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nodejs/node/pulls/6573"},"html":{"href":"https://github.com/nodejs/node/pull/6573"},"issue":{"href":"https://api.github.com/repos/nodejs/node/issues/6573"},"comments":{"href":"https://api.github.com/repos/nodejs/node/issues/6573/comments"},"review_comments":{"href":"https://api.github.com/repos/nodejs/node/pulls/6573/comments"},"review_comment":{"href":"https://api.github.com/repos/nodejs/node/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nodejs/node/pulls/6573/commits"},"statuses":{"href":"https://api.github.com/repos/nodejs/node/statuses/76bc6e617dd5a5934d6e14aa1c62286dcdd954fe"}}}}