{"action":"created","comment":{"url":"https://api.github.com/repos/pingcap/tidb/pulls/comments/43749935","id":43749935,"diff_hunk":"@@ -0,0 +1,111 @@\n+// Copyright 2015 PingCAP, Inc.\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//\n+//     http://www.apache.org/licenses/LICENSE-2.0\n+//\n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+\n+package terror\n+\n+import (\n+\t\"fmt\"\n+\t\"github.com/juju/errors\"\n+\t\"strconv\"\n+)\n+\n+// ErrClass represents a class of errors.\n+type ErrClass int\n+\n+// ErrCode represents a specific error type in a error class.\n+// Same error code can be used in different error classes.\n+type ErrCode int\n+\n+// Error classes\n+const (\n+\tParser ErrClass = iota\n+\tOptimizer\n+\tKV\n+\tServer\n+\t// Add more as needed.\n+)\n+\n+// String implements Stringer interface.\n+func (ec ErrClass) String() string {\n+\tswitch ec {\n+\tcase Parser:\n+\t\treturn \"parser\"\n+\tcase Optimizer:\n+\t\treturn \"optimizer\"\n+\tcase KV:\n+\t\treturn \"kv\"\n+\tcase Server:\n+\t\treturn \"server\"\n+\t}\n+\treturn strconv.Itoa(int(ec))\n+}\n+\n+// EqualCode returns true if err is *Error with the same clase and code.\n+func (ec ErrClass) EqualCode(err error, code ErrCode) bool {\n+\te := errors.Cause(err)\n+\tif e == nil {\n+\t\treturn false\n+\t}\n+\tif te, ok := e.(*Error); ok {\n+\t\treturn te.Class == ec && te.Code == code\n+\t}\n+\treturn false\n+}\n+\n+// NotEqualCode returns true if err is not *Error with the same class\n+// and the same code.\n+func (ec ErrClass) NotEqualCode(err error, code ErrCode) bool {\n+\treturn !ec.EqualCode(err, code)\n+}\n+\n+// EqualClass return true if err is *Error with the same class.\n+func (ec ErrClass) EqualClass(err error) bool {\n+\te := errors.Cause(err)\n+\tif e == nil {\n+\t\treturn false\n+\t}\n+\tif te, ok := e.(*Error); ok {\n+\t\treturn te.Class == ec\n+\t}\n+\treturn false\n+}\n+\n+// NotEqualClass return true if err is not *Error with the same class.\n+func (ec ErrClass) NotEqualClass(err error) bool {\n+\treturn !ec.EqualClass(err)\n+}\n+\n+// New creates an *Error with an error code, message format and arguments.\n+func (ec ErrClass) New(code ErrCode, message string, args ...interface{}) *Error {\n+\tif len(args) != 0 {\n+\t\tmessage = fmt.Sprintf(message, args...)\n+\t}\n+\treturn &Error{\n+\t\tClass:   ec,\n+\t\tCode:    code,\n+\t\tMessage: message,\n+\t}\n+}\n+\n+// Error implements error interface and adds integer Class and Code, so\n+// errors with different message can be compared.\n+type Error struct {\n+\tClass   ErrClass\n+\tCode    ErrCode","path":"terror/terror.go","position":104,"original_position":104,"commit_id":"2957a4a9e11555d2024d56a04f1473a3323dbf15","original_commit_id":"2957a4a9e11555d2024d56a04f1473a3323dbf15","user":{"login":"shenli","id":1192573,"avatar_url":"https://avatars.githubusercontent.com/u/1192573?v=3","gravatar_id":"","url":"https://api.github.com/users/shenli","html_url":"https://github.com/shenli","followers_url":"https://api.github.com/users/shenli/followers","following_url":"https://api.github.com/users/shenli/following{/other_user}","gists_url":"https://api.github.com/users/shenli/gists{/gist_id}","starred_url":"https://api.github.com/users/shenli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shenli/subscriptions","organizations_url":"https://api.github.com/users/shenli/orgs","repos_url":"https://api.github.com/users/shenli/repos","events_url":"https://api.github.com/users/shenli/events{/privacy}","received_events_url":"https://api.github.com/users/shenli/received_events","type":"User","site_admin":false},"body":"Error code is enough?","created_at":"2015-11-03T14:03:57Z","updated_at":"2015-11-03T14:03:57Z","html_url":"https://github.com/pingcap/tidb/pull/509#discussion_r43749935","pull_request_url":"https://api.github.com/repos/pingcap/tidb/pulls/509","_links":{"self":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/comments/43749935"},"html":{"href":"https://github.com/pingcap/tidb/pull/509#discussion_r43749935"},"pull_request":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/509"}}},"pull_request":{"url":"https://api.github.com/repos/pingcap/tidb/pulls/509","id":49538732,"html_url":"https://github.com/pingcap/tidb/pull/509","diff_url":"https://github.com/pingcap/tidb/pull/509.diff","patch_url":"https://github.com/pingcap/tidb/pull/509.patch","issue_url":"https://api.github.com/repos/pingcap/tidb/issues/509","number":509,"state":"open","locked":false,"title":"terror: create a new error type that has class and code for comparison.","user":{"login":"coocood","id":891222,"avatar_url":"https://avatars.githubusercontent.com/u/891222?v=3","gravatar_id":"","url":"https://api.github.com/users/coocood","html_url":"https://github.com/coocood","followers_url":"https://api.github.com/users/coocood/followers","following_url":"https://api.github.com/users/coocood/following{/other_user}","gists_url":"https://api.github.com/users/coocood/gists{/gist_id}","starred_url":"https://api.github.com/users/coocood/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coocood/subscriptions","organizations_url":"https://api.github.com/users/coocood/orgs","repos_url":"https://api.github.com/users/coocood/repos","events_url":"https://api.github.com/users/coocood/events{/privacy}","received_events_url":"https://api.github.com/users/coocood/received_events","type":"User","site_admin":false},"body":"The current error check can only handle errors that has exactly the same message, when error message is not constant. For example parsing error has the message describe the context of the error, we will not be able to check it.. \r\n\r\nWith this error type, we can includes context information in the message and still able to check the error type.","created_at":"2015-11-03T10:26:19Z","updated_at":"2015-11-03T14:03:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a75d750781de90bfc3d6f7aa1d15ed153eb5a73e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/pingcap/tidb/pulls/509/commits","review_comments_url":"https://api.github.com/repos/pingcap/tidb/pulls/509/comments","review_comment_url":"https://api.github.com/repos/pingcap/tidb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pingcap/tidb/issues/509/comments","statuses_url":"https://api.github.com/repos/pingcap/tidb/statuses/2957a4a9e11555d2024d56a04f1473a3323dbf15","head":{"label":"pingcap:coocood/terror","ref":"coocood/terror","sha":"2957a4a9e11555d2024d56a04f1473a3323dbf15","user":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"repo":{"id":41986369,"name":"tidb","full_name":"pingcap/tidb","owner":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pingcap/tidb","description":"TiDB is a distributed SQL database compatible with MySQL protocol.","fork":false,"url":"https://api.github.com/repos/pingcap/tidb","forks_url":"https://api.github.com/repos/pingcap/tidb/forks","keys_url":"https://api.github.com/repos/pingcap/tidb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pingcap/tidb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pingcap/tidb/teams","hooks_url":"https://api.github.com/repos/pingcap/tidb/hooks","issue_events_url":"https://api.github.com/repos/pingcap/tidb/issues/events{/number}","events_url":"https://api.github.com/repos/pingcap/tidb/events","assignees_url":"https://api.github.com/repos/pingcap/tidb/assignees{/user}","branches_url":"https://api.github.com/repos/pingcap/tidb/branches{/branch}","tags_url":"https://api.github.com/repos/pingcap/tidb/tags","blobs_url":"https://api.github.com/repos/pingcap/tidb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pingcap/tidb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pingcap/tidb/git/refs{/sha}","trees_url":"https://api.github.com/repos/pingcap/tidb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pingcap/tidb/statuses/{sha}","languages_url":"https://api.github.com/repos/pingcap/tidb/languages","stargazers_url":"https://api.github.com/repos/pingcap/tidb/stargazers","contributors_url":"https://api.github.com/repos/pingcap/tidb/contributors","subscribers_url":"https://api.github.com/repos/pingcap/tidb/subscribers","subscription_url":"https://api.github.com/repos/pingcap/tidb/subscription","commits_url":"https://api.github.com/repos/pingcap/tidb/commits{/sha}","git_commits_url":"https://api.github.com/repos/pingcap/tidb/git/commits{/sha}","comments_url":"https://api.github.com/repos/pingcap/tidb/comments{/number}","issue_comment_url":"https://api.github.com/repos/pingcap/tidb/issues/comments{/number}","contents_url":"https://api.github.com/repos/pingcap/tidb/contents/{+path}","compare_url":"https://api.github.com/repos/pingcap/tidb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pingcap/tidb/merges","archive_url":"https://api.github.com/repos/pingcap/tidb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pingcap/tidb/downloads","issues_url":"https://api.github.com/repos/pingcap/tidb/issues{/number}","pulls_url":"https://api.github.com/repos/pingcap/tidb/pulls{/number}","milestones_url":"https://api.github.com/repos/pingcap/tidb/milestones{/number}","notifications_url":"https://api.github.com/repos/pingcap/tidb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pingcap/tidb/labels{/name}","releases_url":"https://api.github.com/repos/pingcap/tidb/releases{/id}","created_at":"2015-09-06T04:01:52Z","updated_at":"2015-11-03T05:53:11Z","pushed_at":"2015-11-03T13:43:43Z","git_url":"git://github.com/pingcap/tidb.git","ssh_url":"git@github.com:pingcap/tidb.git","clone_url":"https://github.com/pingcap/tidb.git","svn_url":"https://github.com/pingcap/tidb","homepage":"","size":13431,"stargazers_count":2748,"watchers_count":2748,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":264,"mirror_url":null,"open_issues_count":57,"forks":264,"open_issues":57,"watchers":2748,"default_branch":"master"}},"base":{"label":"pingcap:master","ref":"master","sha":"d87a097271d94f2cb6391c14b281fbb0f48391ee","user":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"repo":{"id":41986369,"name":"tidb","full_name":"pingcap/tidb","owner":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pingcap/tidb","description":"TiDB is a distributed SQL database compatible with MySQL protocol.","fork":false,"url":"https://api.github.com/repos/pingcap/tidb","forks_url":"https://api.github.com/repos/pingcap/tidb/forks","keys_url":"https://api.github.com/repos/pingcap/tidb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pingcap/tidb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pingcap/tidb/teams","hooks_url":"https://api.github.com/repos/pingcap/tidb/hooks","issue_events_url":"https://api.github.com/repos/pingcap/tidb/issues/events{/number}","events_url":"https://api.github.com/repos/pingcap/tidb/events","assignees_url":"https://api.github.com/repos/pingcap/tidb/assignees{/user}","branches_url":"https://api.github.com/repos/pingcap/tidb/branches{/branch}","tags_url":"https://api.github.com/repos/pingcap/tidb/tags","blobs_url":"https://api.github.com/repos/pingcap/tidb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pingcap/tidb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pingcap/tidb/git/refs{/sha}","trees_url":"https://api.github.com/repos/pingcap/tidb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pingcap/tidb/statuses/{sha}","languages_url":"https://api.github.com/repos/pingcap/tidb/languages","stargazers_url":"https://api.github.com/repos/pingcap/tidb/stargazers","contributors_url":"https://api.github.com/repos/pingcap/tidb/contributors","subscribers_url":"https://api.github.com/repos/pingcap/tidb/subscribers","subscription_url":"https://api.github.com/repos/pingcap/tidb/subscription","commits_url":"https://api.github.com/repos/pingcap/tidb/commits{/sha}","git_commits_url":"https://api.github.com/repos/pingcap/tidb/git/commits{/sha}","comments_url":"https://api.github.com/repos/pingcap/tidb/comments{/number}","issue_comment_url":"https://api.github.com/repos/pingcap/tidb/issues/comments{/number}","contents_url":"https://api.github.com/repos/pingcap/tidb/contents/{+path}","compare_url":"https://api.github.com/repos/pingcap/tidb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pingcap/tidb/merges","archive_url":"https://api.github.com/repos/pingcap/tidb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pingcap/tidb/downloads","issues_url":"https://api.github.com/repos/pingcap/tidb/issues{/number}","pulls_url":"https://api.github.com/repos/pingcap/tidb/pulls{/number}","milestones_url":"https://api.github.com/repos/pingcap/tidb/milestones{/number}","notifications_url":"https://api.github.com/repos/pingcap/tidb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pingcap/tidb/labels{/name}","releases_url":"https://api.github.com/repos/pingcap/tidb/releases{/id}","created_at":"2015-09-06T04:01:52Z","updated_at":"2015-11-03T05:53:11Z","pushed_at":"2015-11-03T13:43:43Z","git_url":"git://github.com/pingcap/tidb.git","ssh_url":"git@github.com:pingcap/tidb.git","clone_url":"https://github.com/pingcap/tidb.git","svn_url":"https://github.com/pingcap/tidb","homepage":"","size":13431,"stargazers_count":2748,"watchers_count":2748,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":264,"mirror_url":null,"open_issues_count":57,"forks":264,"open_issues":57,"watchers":2748,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/509"},"html":{"href":"https://github.com/pingcap/tidb/pull/509"},"issue":{"href":"https://api.github.com/repos/pingcap/tidb/issues/509"},"comments":{"href":"https://api.github.com/repos/pingcap/tidb/issues/509/comments"},"review_comments":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/509/comments"},"review_comment":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/509/commits"},"statuses":{"href":"https://api.github.com/repos/pingcap/tidb/statuses/2957a4a9e11555d2024d56a04f1473a3323dbf15"}}}}