{"action":"created","comment":{"url":"https://api.github.com/repos/realm/realm-cocoa/pulls/comments/35042784","id":35042784,"diff_hunk":"@@ -17,29 +17,112 @@\n ////////////////////////////////////////////////////////////////////////////\n \n #include \"object_store_exceptions.hpp\"\n+#include \"property.hpp\"\n+\n+#include <realm/util/assert.hpp>\n+#include <regex>\n \n using namespace realm;\n using namespace std;\n \n-ObjectStoreException::ObjectStoreException(Kind kind, Dict dict) : m_kind(kind), m_dict(dict) {\n-    switch (m_kind) {\n-        case Kind::RealmVersionGreaterThanSchemaVersion:\n-            m_what = \"Provided schema version \" + m_dict.at(\"old_version\") + \" is less than last set version \" + m_dict.at(\"new_version\") + \".\";\n-            break;\n-        case Kind::RealmPropertyTypeNotIndexable:\n-            m_what = \"Can't index property '\" + m_dict.at(\"object_type\") + \".\" + m_dict.at(\"property_name\") + \"': \" +\n-                     \"indexing properties of type '\" + m_dict.at(\"property_type\") + \"' is currently not supported\";\n-            break;\n-        case Kind::RealmDuplicatePrimaryKeyValue:\n-            m_what = \"Primary key property '\" + m_dict[\"property_name\"] + \"' has duplicate values after migration.\";\n-            break;\n+ObjectStoreException::ObjectStoreException(Kind kind, Info info) : m_kind(kind), m_info(info), m_what(generate_what()) {}\n+\n+ObjectStoreException::ObjectStoreException(Kind kind, const std::string &object_type, const Property &prop) : m_kind(kind) {\n+    m_info[InfoKeyObjectType] = object_type;\n+    m_info[InfoKeyPropertyName] = prop.name;\n+    m_info[InfoKeyPropertyType] = string_for_property_type(prop.type);\n+    m_info[InfoKeyPropertyObjectType] = prop.object_type;\n+    m_what = generate_what();\n+}\n+\n+ObjectStoreException::ObjectStoreException(Kind kind, const std::string &object_type, const Property &prop, const Property &oldProp) :\n+    m_kind(kind) {\n+    m_info[InfoKeyObjectType] = object_type;\n+    m_info[InfoKeyPropertyName] = prop.name;\n+    m_info[InfoKeyPropertyType] = string_for_property_type(prop.type);\n+    m_info[InfoKeyOldPropertyType] = string_for_property_type(oldProp.type);\n+    m_info[InfoKeyPropertyObjectType] = prop.object_type;\n+    m_info[InfoKeyOldPropertyObjectType] = oldProp.object_type;\n+    m_what = generate_what();\n+}\n+\n+ObjectStoreException::ObjectStoreException(Kind kind, const std::string &object_type, const std::string primary_key) : m_kind(kind) {\n+    m_info[InfoKeyObjectType] = object_type;\n+    m_info[InfoKeyPrimaryKey] = primary_key;\n+    m_what = generate_what();\n+}\n+\n+ObjectStoreException::ObjectStoreException(uint64_t old_version, uint64_t new_version) : m_kind(Kind::RealmVersionGreaterThanSchemaVersion) {\n+    m_info[InfoKeyOldVersion] = to_string(old_version);\n+    m_info[InfoKeyNewVersion] = to_string(new_version);\n+    m_what = generate_what();\n+}\n+\n+ObjectStoreException::ObjectStoreException(vector<ObjectStoreException> validation_errors, const string &object_type) :\n+    m_validation_errors(validation_errors), m_kind(Kind::ObjectStoreValidationFailure) {\n+    m_info[InfoKeyObjectType] = object_type;\n+    m_what = generate_what();\n+}\n+\n+string ObjectStoreException::generate_what() const {\n+    auto format_string = s_custom_format_strings.find(m_kind);\n+    if (format_string != s_custom_format_strings.end()) {\n+        return populate_format_string(format_string->second);\n     }\n+    return populate_format_string(s_default_format_strings.at(m_kind));\n }\n \n-ObjectStoreValidationException::ObjectStoreValidationException(std::vector<std::string> validation_errors, std::string object_type) :\n-    m_validation_errors(validation_errors), m_object_type(object_type) {\n-    m_what = \"Migration is required for object type '\" + m_object_type + \"' due to the following errors:\";\n+string ObjectStoreException::validation_errors_string() const {\n+    string errors_string;\n     for (auto error : m_validation_errors) {\n-        m_what += \"\\n- \" + error;\n+        errors_string += string(\"\\n- \") + error.what();\n     }\n+    return errors_string;\n }\n+\n+std::string ObjectStoreException::populate_format_string(const std::string & format_string) const {\n+    string out_string, current(format_string);\n+    smatch sm;\n+    regex re(\"\\\\{(\\\\w+)\\\\}\");","path":"Realm/ObjectStore/object_store_exceptions.cpp","position":86,"original_position":86,"commit_id":"cc17342ef65ca0c238a43bf48bbf2a01ba98750e","original_commit_id":"cc17342ef65ca0c238a43bf48bbf2a01ba98750e","user":{"login":"simonask","id":23115,"avatar_url":"https://avatars.githubusercontent.com/u/23115?v=3","gravatar_id":"","url":"https://api.github.com/users/simonask","html_url":"https://github.com/simonask","followers_url":"https://api.github.com/users/simonask/followers","following_url":"https://api.github.com/users/simonask/following{/other_user}","gists_url":"https://api.github.com/users/simonask/gists{/gist_id}","starred_url":"https://api.github.com/users/simonask/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simonask/subscriptions","organizations_url":"https://api.github.com/users/simonask/orgs","repos_url":"https://api.github.com/users/simonask/repos","events_url":"https://api.github.com/users/simonask/events{/privacy}","received_events_url":"https://api.github.com/users/simonask/received_events","type":"User","site_admin":false},"body":"Please verify that `std::regex` is working with this expression on all platforms. I've had trouble in the past with GCC, but I'm especially worried about MSVC. :)","created_at":"2015-07-20T20:53:55Z","updated_at":"2015-07-20T20:53:55Z","html_url":"https://github.com/realm/realm-cocoa/pull/2252#discussion_r35042784","pull_request_url":"https://api.github.com/repos/realm/realm-cocoa/pulls/2252","_links":{"self":{"href":"https://api.github.com/repos/realm/realm-cocoa/pulls/comments/35042784"},"html":{"href":"https://github.com/realm/realm-cocoa/pull/2252#discussion_r35042784"},"pull_request":{"href":"https://api.github.com/repos/realm/realm-cocoa/pulls/2252"}}},"pull_request":{"url":"https://api.github.com/repos/realm/realm-cocoa/pulls/2252","id":40389964,"html_url":"https://github.com/realm/realm-cocoa/pull/2252","diff_url":"https://github.com/realm/realm-cocoa/pull/2252.diff","patch_url":"https://github.com/realm/realm-cocoa/pull/2252.patch","issue_url":"https://api.github.com/repos/realm/realm-cocoa/issues/2252","number":2252,"state":"open","locked":false,"title":"[WIP] Move common Realm functionality to new class realm::Realm","user":{"login":"alazier","id":250144,"avatar_url":"https://avatars.githubusercontent.com/u/250144?v=3","gravatar_id":"","url":"https://api.github.com/users/alazier","html_url":"https://github.com/alazier","followers_url":"https://api.github.com/users/alazier/followers","following_url":"https://api.github.com/users/alazier/following{/other_user}","gists_url":"https://api.github.com/users/alazier/gists{/gist_id}","starred_url":"https://api.github.com/users/alazier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alazier/subscriptions","organizations_url":"https://api.github.com/users/alazier/orgs","repos_url":"https://api.github.com/users/alazier/repos","events_url":"https://api.github.com/users/alazier/events{/privacy}","received_events_url":"https://api.github.com/users/alazier/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-07-20T19:51:36Z","updated_at":"2015-07-20T20:53:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cbb180e61b0919fe14c4247588ab51bdcb231d02","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/realm/realm-cocoa/pulls/2252/commits","review_comments_url":"https://api.github.com/repos/realm/realm-cocoa/pulls/2252/comments","review_comment_url":"https://api.github.com/repos/realm/realm-cocoa/pulls/comments{/number}","comments_url":"https://api.github.com/repos/realm/realm-cocoa/issues/2252/comments","statuses_url":"https://api.github.com/repos/realm/realm-cocoa/statuses/cc17342ef65ca0c238a43bf48bbf2a01ba98750e","head":{"label":"realm:al-realm","ref":"al-realm","sha":"cc17342ef65ca0c238a43bf48bbf2a01ba98750e","user":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"repo":{"id":4044891,"name":"realm-cocoa","full_name":"realm/realm-cocoa","owner":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/realm/realm-cocoa","description":"Realm is a mobile database: a replacement for Core Data & SQLite","fork":false,"url":"https://api.github.com/repos/realm/realm-cocoa","forks_url":"https://api.github.com/repos/realm/realm-cocoa/forks","keys_url":"https://api.github.com/repos/realm/realm-cocoa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/realm/realm-cocoa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/realm/realm-cocoa/teams","hooks_url":"https://api.github.com/repos/realm/realm-cocoa/hooks","issue_events_url":"https://api.github.com/repos/realm/realm-cocoa/issues/events{/number}","events_url":"https://api.github.com/repos/realm/realm-cocoa/events","assignees_url":"https://api.github.com/repos/realm/realm-cocoa/assignees{/user}","branches_url":"https://api.github.com/repos/realm/realm-cocoa/branches{/branch}","tags_url":"https://api.github.com/repos/realm/realm-cocoa/tags","blobs_url":"https://api.github.com/repos/realm/realm-cocoa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/realm/realm-cocoa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/realm/realm-cocoa/git/refs{/sha}","trees_url":"https://api.github.com/repos/realm/realm-cocoa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/realm/realm-cocoa/statuses/{sha}","languages_url":"https://api.github.com/repos/realm/realm-cocoa/languages","stargazers_url":"https://api.github.com/repos/realm/realm-cocoa/stargazers","contributors_url":"https://api.github.com/repos/realm/realm-cocoa/contributors","subscribers_url":"https://api.github.com/repos/realm/realm-cocoa/subscribers","subscription_url":"https://api.github.com/repos/realm/realm-cocoa/subscription","commits_url":"https://api.github.com/repos/realm/realm-cocoa/commits{/sha}","git_commits_url":"https://api.github.com/repos/realm/realm-cocoa/git/commits{/sha}","comments_url":"https://api.github.com/repos/realm/realm-cocoa/comments{/number}","issue_comment_url":"https://api.github.com/repos/realm/realm-cocoa/issues/comments{/number}","contents_url":"https://api.github.com/repos/realm/realm-cocoa/contents/{+path}","compare_url":"https://api.github.com/repos/realm/realm-cocoa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/realm/realm-cocoa/merges","archive_url":"https://api.github.com/repos/realm/realm-cocoa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/realm/realm-cocoa/downloads","issues_url":"https://api.github.com/repos/realm/realm-cocoa/issues{/number}","pulls_url":"https://api.github.com/repos/realm/realm-cocoa/pulls{/number}","milestones_url":"https://api.github.com/repos/realm/realm-cocoa/milestones{/number}","notifications_url":"https://api.github.com/repos/realm/realm-cocoa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/realm/realm-cocoa/labels{/name}","releases_url":"https://api.github.com/repos/realm/realm-cocoa/releases{/id}","created_at":"2012-04-16T20:06:56Z","updated_at":"2015-07-20T20:28:01Z","pushed_at":"2015-07-20T20:53:00Z","git_url":"git://github.com/realm/realm-cocoa.git","ssh_url":"git@github.com:realm/realm-cocoa.git","clone_url":"https://github.com/realm/realm-cocoa.git","svn_url":"https://github.com/realm/realm-cocoa","homepage":"https://realm.io","size":115294,"stargazers_count":4202,"watchers_count":4202,"language":"Swift","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":365,"mirror_url":null,"open_issues_count":164,"forks":365,"open_issues":164,"watchers":4202,"default_branch":"master"}},"base":{"label":"realm:master","ref":"master","sha":"040bc0325a36b54605f8e806b8b4898fe3965061","user":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"repo":{"id":4044891,"name":"realm-cocoa","full_name":"realm/realm-cocoa","owner":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/realm/realm-cocoa","description":"Realm is a mobile database: a replacement for Core Data & SQLite","fork":false,"url":"https://api.github.com/repos/realm/realm-cocoa","forks_url":"https://api.github.com/repos/realm/realm-cocoa/forks","keys_url":"https://api.github.com/repos/realm/realm-cocoa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/realm/realm-cocoa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/realm/realm-cocoa/teams","hooks_url":"https://api.github.com/repos/realm/realm-cocoa/hooks","issue_events_url":"https://api.github.com/repos/realm/realm-cocoa/issues/events{/number}","events_url":"https://api.github.com/repos/realm/realm-cocoa/events","assignees_url":"https://api.github.com/repos/realm/realm-cocoa/assignees{/user}","branches_url":"https://api.github.com/repos/realm/realm-cocoa/branches{/branch}","tags_url":"https://api.github.com/repos/realm/realm-cocoa/tags","blobs_url":"https://api.github.com/repos/realm/realm-cocoa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/realm/realm-cocoa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/realm/realm-cocoa/git/refs{/sha}","trees_url":"https://api.github.com/repos/realm/realm-cocoa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/realm/realm-cocoa/statuses/{sha}","languages_url":"https://api.github.com/repos/realm/realm-cocoa/languages","stargazers_url":"https://api.github.com/repos/realm/realm-cocoa/stargazers","contributors_url":"https://api.github.com/repos/realm/realm-cocoa/contributors","subscribers_url":"https://api.github.com/repos/realm/realm-cocoa/subscribers","subscription_url":"https://api.github.com/repos/realm/realm-cocoa/subscription","commits_url":"https://api.github.com/repos/realm/realm-cocoa/commits{/sha}","git_commits_url":"https://api.github.com/repos/realm/realm-cocoa/git/commits{/sha}","comments_url":"https://api.github.com/repos/realm/realm-cocoa/comments{/number}","issue_comment_url":"https://api.github.com/repos/realm/realm-cocoa/issues/comments{/number}","contents_url":"https://api.github.com/repos/realm/realm-cocoa/contents/{+path}","compare_url":"https://api.github.com/repos/realm/realm-cocoa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/realm/realm-cocoa/merges","archive_url":"https://api.github.com/repos/realm/realm-cocoa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/realm/realm-cocoa/downloads","issues_url":"https://api.github.com/repos/realm/realm-cocoa/issues{/number}","pulls_url":"https://api.github.com/repos/realm/realm-cocoa/pulls{/number}","milestones_url":"https://api.github.com/repos/realm/realm-cocoa/milestones{/number}","notifications_url":"https://api.github.com/repos/realm/realm-cocoa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/realm/realm-cocoa/labels{/name}","releases_url":"https://api.github.com/repos/realm/realm-cocoa/releases{/id}","created_at":"2012-04-16T20:06:56Z","updated_at":"2015-07-20T20:28:01Z","pushed_at":"2015-07-20T20:53:00Z","git_url":"git://github.com/realm/realm-cocoa.git","ssh_url":"git@github.com:realm/realm-cocoa.git","clone_url":"https://github.com/realm/realm-cocoa.git","svn_url":"https://github.com/realm/realm-cocoa","homepage":"https://realm.io","size":115294,"stargazers_count":4202,"watchers_count":4202,"language":"Swift","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":365,"mirror_url":null,"open_issues_count":164,"forks":365,"open_issues":164,"watchers":4202,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/realm/realm-cocoa/pulls/2252"},"html":{"href":"https://github.com/realm/realm-cocoa/pull/2252"},"issue":{"href":"https://api.github.com/repos/realm/realm-cocoa/issues/2252"},"comments":{"href":"https://api.github.com/repos/realm/realm-cocoa/issues/2252/comments"},"review_comments":{"href":"https://api.github.com/repos/realm/realm-cocoa/pulls/2252/comments"},"review_comment":{"href":"https://api.github.com/repos/realm/realm-cocoa/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/realm/realm-cocoa/pulls/2252/commits"},"statuses":{"href":"https://api.github.com/repos/realm/realm-cocoa/statuses/cc17342ef65ca0c238a43bf48bbf2a01ba98750e"}}}}