{"action":"created","comment":{"url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/pulls/comments/51134848","id":51134848,"diff_hunk":"@@ -0,0 +1,119 @@\n+// Copyright 2015 MongoDB 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+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+\n+#include <cstdlib>\n+#include <iostream>\n+\n+#include <bsoncxx/builder/stream/document.hpp>\n+#include <bsoncxx/json.hpp>\n+#include <mongocxx/client.hpp>\n+#include <mongocxx/exception/bulk_write_exception.hpp>\n+#include <mongocxx/exception/error_code.hpp>\n+#include <mongocxx/exception/server_error_code.hpp>\n+#include <mongocxx/exception/logic_error.hpp>\n+#include <mongocxx/exception/operation_exception.hpp>\n+#include <mongocxx/instance.hpp>\n+#include <mongocxx/uri.hpp>\n+\n+using bsoncxx::builder::stream::close_document;\n+using bsoncxx::builder::stream::document;\n+using bsoncxx::builder::stream::finalize;\n+using bsoncxx::builder::stream::open_document;\n+\n+int main(int, char**) {","path":"examples/mongocxx/exception.cpp","position":34,"original_position":34,"commit_id":"5f0d47942b20fbe2b85b72189ca5dfd7b80bebed","original_commit_id":"5f0d47942b20fbe2b85b72189ca5dfd7b80bebed","user":{"login":"tessavitabile","id":13758212,"avatar_url":"https://avatars.githubusercontent.com/u/13758212?v=3","gravatar_id":"","url":"https://api.github.com/users/tessavitabile","html_url":"https://github.com/tessavitabile","followers_url":"https://api.github.com/users/tessavitabile/followers","following_url":"https://api.github.com/users/tessavitabile/following{/other_user}","gists_url":"https://api.github.com/users/tessavitabile/gists{/gist_id}","starred_url":"https://api.github.com/users/tessavitabile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tessavitabile/subscriptions","organizations_url":"https://api.github.com/users/tessavitabile/orgs","repos_url":"https://api.github.com/users/tessavitabile/repos","events_url":"https://api.github.com/users/tessavitabile/events{/privacy}","received_events_url":"https://api.github.com/users/tessavitabile/received_events","type":"User","site_admin":false},"body":"Should this example also include how you would do error-handling in \"real code\"? That was something I was planning to add.","created_at":"2016-01-28T15:16:19Z","updated_at":"2016-01-28T15:16:19Z","html_url":"https://github.com/mongodb/mongo-cxx-driver/pull/454#discussion_r51134848","pull_request_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/pulls/454","_links":{"self":{"href":"https://api.github.com/repos/mongodb/mongo-cxx-driver/pulls/comments/51134848"},"html":{"href":"https://github.com/mongodb/mongo-cxx-driver/pull/454#discussion_r51134848"},"pull_request":{"href":"https://api.github.com/repos/mongodb/mongo-cxx-driver/pulls/454"}}},"pull_request":{"url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/pulls/454","id":57455983,"html_url":"https://github.com/mongodb/mongo-cxx-driver/pull/454","diff_url":"https://github.com/mongodb/mongo-cxx-driver/pull/454.diff","patch_url":"https://github.com/mongodb/mongo-cxx-driver/pull/454.patch","issue_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/issues/454","number":454,"state":"open","locked":false,"title":"CXX-754 Radically simplify bsoncxx/mongocxx exceptions and error_codes","user":{"login":"acmorrow","id":268253,"avatar_url":"https://avatars.githubusercontent.com/u/268253?v=3","gravatar_id":"","url":"https://api.github.com/users/acmorrow","html_url":"https://github.com/acmorrow","followers_url":"https://api.github.com/users/acmorrow/followers","following_url":"https://api.github.com/users/acmorrow/following{/other_user}","gists_url":"https://api.github.com/users/acmorrow/gists{/gist_id}","starred_url":"https://api.github.com/users/acmorrow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/acmorrow/subscriptions","organizations_url":"https://api.github.com/users/acmorrow/orgs","repos_url":"https://api.github.com/users/acmorrow/repos","events_url":"https://api.github.com/users/acmorrow/events{/privacy}","received_events_url":"https://api.github.com/users/acmorrow/received_events","type":"User","site_admin":false},"body":"This is the first proposed change in the error handling refactor. While investigating what we needed to do for mongocxx, it was clear we should start with bsoncxx.\r\n\r\nI'll be stacking more commits above this, but this describes the first one. It does several things:\r\n\r\n- It eliminates the other error_categories. We care about only one error coming back from libbson, which is \"I couldn't parse your JSON\". By removing the other error_categories and just adding a new code of our own to express that, we make it so we don't leak any of libbson's error handling abstractions\r\n- It makes public the make_error_code overload, and specializes the is_error_code_enum, allowing ADL-ified construction and comparison. Nowhere do you now need to invoke make_error_code.\r\n- Removes all of the exception stuff that was previously private.\r\n\r\nIf, later, we find that we need to express other libbson errors, we will write our own new codes for them in the one error_category.\r\n\r\nI plan to pursue a similar strategy to this in mongocxx, though it will necessarily be more complex.","created_at":"2016-01-28T05:01:12Z","updated_at":"2016-01-28T15:16:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c7fdf2642e710429bff6cedfef252a86b9d20434","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/pulls/454/commits","review_comments_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/pulls/454/comments","review_comment_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/issues/454/comments","statuses_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/statuses/5f0d47942b20fbe2b85b72189ca5dfd7b80bebed","head":{"label":"acmorrow:CXX-754","ref":"CXX-754","sha":"5f0d47942b20fbe2b85b72189ca5dfd7b80bebed","user":{"login":"acmorrow","id":268253,"avatar_url":"https://avatars.githubusercontent.com/u/268253?v=3","gravatar_id":"","url":"https://api.github.com/users/acmorrow","html_url":"https://github.com/acmorrow","followers_url":"https://api.github.com/users/acmorrow/followers","following_url":"https://api.github.com/users/acmorrow/following{/other_user}","gists_url":"https://api.github.com/users/acmorrow/gists{/gist_id}","starred_url":"https://api.github.com/users/acmorrow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/acmorrow/subscriptions","organizations_url":"https://api.github.com/users/acmorrow/orgs","repos_url":"https://api.github.com/users/acmorrow/repos","events_url":"https://api.github.com/users/acmorrow/events{/privacy}","received_events_url":"https://api.github.com/users/acmorrow/received_events","type":"User","site_admin":false},"repo":{"id":17258919,"name":"mongo-cxx-driver","full_name":"acmorrow/mongo-cxx-driver","owner":{"login":"acmorrow","id":268253,"avatar_url":"https://avatars.githubusercontent.com/u/268253?v=3","gravatar_id":"","url":"https://api.github.com/users/acmorrow","html_url":"https://github.com/acmorrow","followers_url":"https://api.github.com/users/acmorrow/followers","following_url":"https://api.github.com/users/acmorrow/following{/other_user}","gists_url":"https://api.github.com/users/acmorrow/gists{/gist_id}","starred_url":"https://api.github.com/users/acmorrow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/acmorrow/subscriptions","organizations_url":"https://api.github.com/users/acmorrow/orgs","repos_url":"https://api.github.com/users/acmorrow/repos","events_url":"https://api.github.com/users/acmorrow/events{/privacy}","received_events_url":"https://api.github.com/users/acmorrow/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/acmorrow/mongo-cxx-driver","description":"C++ Driver for MongoDB","fork":true,"url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver","forks_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/forks","keys_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/keys{/key_id}","collaborators_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/teams","hooks_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/hooks","issue_events_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/issues/events{/number}","events_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/events","assignees_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/assignees{/user}","branches_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/branches{/branch}","tags_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/tags","blobs_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/git/refs{/sha}","trees_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/git/trees{/sha}","statuses_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/statuses/{sha}","languages_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/languages","stargazers_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/stargazers","contributors_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/contributors","subscribers_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/subscribers","subscription_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/subscription","commits_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/commits{/sha}","git_commits_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/git/commits{/sha}","comments_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/comments{/number}","issue_comment_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/issues/comments{/number}","contents_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/contents/{+path}","compare_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/compare/{base}...{head}","merges_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/merges","archive_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/downloads","issues_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/issues{/number}","pulls_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/pulls{/number}","milestones_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/milestones{/number}","notifications_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/labels{/name}","releases_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/releases{/id}","deployments_url":"https://api.github.com/repos/acmorrow/mongo-cxx-driver/deployments","created_at":"2014-02-27T18:14:36Z","updated_at":"2015-04-24T17:44:13Z","pushed_at":"2016-01-28T06:53:46Z","git_url":"git://github.com/acmorrow/mongo-cxx-driver.git","ssh_url":"git@github.com:acmorrow/mongo-cxx-driver.git","clone_url":"https://github.com/acmorrow/mongo-cxx-driver.git","svn_url":"https://github.com/acmorrow/mongo-cxx-driver","homepage":null,"size":5908,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mongodb:master","ref":"master","sha":"3c13b041e8106754ebec0851d786da2399a76804","user":{"login":"mongodb","id":45120,"avatar_url":"https://avatars.githubusercontent.com/u/45120?v=3","gravatar_id":"","url":"https://api.github.com/users/mongodb","html_url":"https://github.com/mongodb","followers_url":"https://api.github.com/users/mongodb/followers","following_url":"https://api.github.com/users/mongodb/following{/other_user}","gists_url":"https://api.github.com/users/mongodb/gists{/gist_id}","starred_url":"https://api.github.com/users/mongodb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mongodb/subscriptions","organizations_url":"https://api.github.com/users/mongodb/orgs","repos_url":"https://api.github.com/users/mongodb/repos","events_url":"https://api.github.com/users/mongodb/events{/privacy}","received_events_url":"https://api.github.com/users/mongodb/received_events","type":"Organization","site_admin":false},"repo":{"id":15881868,"name":"mongo-cxx-driver","full_name":"mongodb/mongo-cxx-driver","owner":{"login":"mongodb","id":45120,"avatar_url":"https://avatars.githubusercontent.com/u/45120?v=3","gravatar_id":"","url":"https://api.github.com/users/mongodb","html_url":"https://github.com/mongodb","followers_url":"https://api.github.com/users/mongodb/followers","following_url":"https://api.github.com/users/mongodb/following{/other_user}","gists_url":"https://api.github.com/users/mongodb/gists{/gist_id}","starred_url":"https://api.github.com/users/mongodb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mongodb/subscriptions","organizations_url":"https://api.github.com/users/mongodb/orgs","repos_url":"https://api.github.com/users/mongodb/repos","events_url":"https://api.github.com/users/mongodb/events{/privacy}","received_events_url":"https://api.github.com/users/mongodb/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mongodb/mongo-cxx-driver","description":"C++ Driver for MongoDB","fork":false,"url":"https://api.github.com/repos/mongodb/mongo-cxx-driver","forks_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/forks","keys_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/teams","hooks_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/hooks","issue_events_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/issues/events{/number}","events_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/events","assignees_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/assignees{/user}","branches_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/branches{/branch}","tags_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/tags","blobs_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/git/refs{/sha}","trees_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/statuses/{sha}","languages_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/languages","stargazers_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/stargazers","contributors_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/contributors","subscribers_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/subscribers","subscription_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/subscription","commits_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/commits{/sha}","git_commits_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/git/commits{/sha}","comments_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/comments{/number}","issue_comment_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/issues/comments{/number}","contents_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/contents/{+path}","compare_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/merges","archive_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/downloads","issues_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/issues{/number}","pulls_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/pulls{/number}","milestones_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/milestones{/number}","notifications_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/labels{/name}","releases_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/releases{/id}","deployments_url":"https://api.github.com/repos/mongodb/mongo-cxx-driver/deployments","created_at":"2014-01-13T21:08:36Z","updated_at":"2016-01-28T10:39:55Z","pushed_at":"2016-01-28T06:50:23Z","git_url":"git://github.com/mongodb/mongo-cxx-driver.git","ssh_url":"git@github.com:mongodb/mongo-cxx-driver.git","clone_url":"https://github.com/mongodb/mongo-cxx-driver.git","svn_url":"https://github.com/mongodb/mongo-cxx-driver","homepage":null,"size":7747,"stargazers_count":224,"watchers_count":224,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":197,"mirror_url":null,"open_issues_count":6,"forks":197,"open_issues":6,"watchers":224,"default_branch":"legacy"}},"_links":{"self":{"href":"https://api.github.com/repos/mongodb/mongo-cxx-driver/pulls/454"},"html":{"href":"https://github.com/mongodb/mongo-cxx-driver/pull/454"},"issue":{"href":"https://api.github.com/repos/mongodb/mongo-cxx-driver/issues/454"},"comments":{"href":"https://api.github.com/repos/mongodb/mongo-cxx-driver/issues/454/comments"},"review_comments":{"href":"https://api.github.com/repos/mongodb/mongo-cxx-driver/pulls/454/comments"},"review_comment":{"href":"https://api.github.com/repos/mongodb/mongo-cxx-driver/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mongodb/mongo-cxx-driver/pulls/454/commits"},"statuses":{"href":"https://api.github.com/repos/mongodb/mongo-cxx-driver/statuses/5f0d47942b20fbe2b85b72189ca5dfd7b80bebed"}}}}