{"action":"created","comment":{"url":"https://api.github.com/repos/hyperledger/iroha/pulls/comments/166090096","pull_request_review_id":94111385,"id":166090096,"diff_hunk":"@@ -97,91 +162,184 @@ namespace iroha {\n           // Transaction counter\n           + transaction_.quote(default_tx_counter) + \", \"\n           + transaction_.quote(account.json_data) + \");\");\n+\n+      auto message_gen = [&] {\n+        return (boost::format(\"failed to insert account, \"\n+                              \"account id: '%s', \"\n+                              \"domain id: '%s', \"\n+                              \"quorum: '%d', \"\n+                              \"transaction counter: '%d', \"\n+                              \"json_data: %s\")\n+                % account.account_id % account.domain_id % account.quorum\n+                % default_tx_counter % account.json_data)\n+            .str();\n+      };\n+\n+      return makeCommandResult(result, message_gen);\n     }\n \n-    bool PostgresWsvCommand::insertAsset(const model::Asset &asset) {\n+    WsvCommandResult PostgresWsvCommand::insertAsset(\n+        const model::Asset &asset) {\n       uint32_t precision = asset.precision;\n-      return execute(\n+      auto result = execute_(\n           \"INSERT INTO asset(asset_id, domain_id, \\\"precision\\\", data) \"\n           \"VALUES (\"\n           + transaction_.quote(asset.asset_id) + \", \"\n           + transaction_.quote(asset.domain_id) + \", \"\n           + transaction_.quote(precision) + \", \" + /*asset.data*/ \"NULL\"\n           + \");\");\n+\n+      auto message_gen = [&] {\n+        return (boost::format(\"failed to insert asset, asset id: '%s', \"\n+                              \"domain id: '%s', precision: %d\")\n+                % asset.asset_id % asset.domain_id % precision)\n+            .str();\n+      };\n+\n+      return makeCommandResult(result, message_gen);\n     }\n \n-    bool PostgresWsvCommand::upsertAccountAsset(\n+    WsvCommandResult PostgresWsvCommand::upsertAccountAsset(\n         const model::AccountAsset &asset) {\n-      return execute(\n+      auto result = execute_(\n             \"INSERT INTO account_has_asset(account_id, asset_id, amount) \"\n             \"VALUES (\"\n             + transaction_.quote(asset.account_id) + \", \"\n             + transaction_.quote(asset.asset_id) + \", \"\n             + transaction_.quote(asset.balance.to_string())\n             + \") ON CONFLICT (account_id, asset_id) DO UPDATE SET \"\n             \"amount = EXCLUDED.amount;\");\n+\n+      auto message_gen = [&] {\n+        return (boost::format(\"failed to upsert account, account id: '%s', \"\n+                              \"asset id: '%s', balance: %s\")\n+                % asset.account_id % asset.asset_id % asset.balance.to_string())\n+            .str();\n+      };\n+\n+      return makeCommandResult(result, message_gen);\n     }\n \n-    bool PostgresWsvCommand::insertSignatory(const pubkey_t &signatory) {\n-      return execute(\"INSERT INTO signatory(public_key) VALUES (\"\n-                     + transaction_.quote(pqxx::binarystring(signatory.data(),\n-                                                             signatory.size()))\n-                     + \") ON CONFLICT DO NOTHING;\");\n+    WsvCommandResult PostgresWsvCommand::insertSignatory(\n+        const pubkey_t &signatory) {\n+      auto result = execute_(\"INSERT INTO signatory(public_key) VALUES (\"\n+                             + transaction_.quote(pqxx::binarystring(\n+                                   signatory.data(), signatory.size()))\n+                             + \") ON CONFLICT DO NOTHING;\");\n+\n+      auto message_gen = [&] {\n+        return (boost::format(\"failed to insert signatory, hex string: '%s'\")","path":"irohad/ametsuchi/impl/postgres_wsv_command.cpp","position":246,"original_position":246,"commit_id":"9d3da24cac835821e97937d6de3f26feda6028f4","original_commit_id":"9d3da24cac835821e97937d6de3f26feda6028f4","user":{"login":"l4l","id":5658339,"avatar_url":"https://avatars2.githubusercontent.com/u/5658339?v=4","gravatar_id":"","url":"https://api.github.com/users/l4l","html_url":"https://github.com/l4l","followers_url":"https://api.github.com/users/l4l/followers","following_url":"https://api.github.com/users/l4l/following{/other_user}","gists_url":"https://api.github.com/users/l4l/gists{/gist_id}","starred_url":"https://api.github.com/users/l4l/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/l4l/subscriptions","organizations_url":"https://api.github.com/users/l4l/orgs","repos_url":"https://api.github.com/users/l4l/repos","events_url":"https://api.github.com/users/l4l/events{/privacy}","received_events_url":"https://api.github.com/users/l4l/received_events","type":"User","site_admin":false},"body":"Not really sure that format should be written as well, imo just `\"failed to insert signatory, signatory: '%s'\"` is better and more consistent","created_at":"2018-02-05T19:41:58Z","updated_at":"2018-02-05T19:57:39Z","html_url":"https://github.com/hyperledger/iroha/pull/940#discussion_r166090096","pull_request_url":"https://api.github.com/repos/hyperledger/iroha/pulls/940","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/hyperledger/iroha/pulls/comments/166090096"},"html":{"href":"https://github.com/hyperledger/iroha/pull/940#discussion_r166090096"},"pull_request":{"href":"https://api.github.com/repos/hyperledger/iroha/pulls/940"}},"in_reply_to_id":166089482},"pull_request":{"url":"https://api.github.com/repos/hyperledger/iroha/pulls/940","id":166847275,"html_url":"https://github.com/hyperledger/iroha/pull/940","diff_url":"https://github.com/hyperledger/iroha/pull/940.diff","patch_url":"https://github.com/hyperledger/iroha/pull/940.patch","issue_url":"https://api.github.com/repos/hyperledger/iroha/issues/940","number":940,"state":"open","locked":false,"title":"WsvCommand returns result instead of optional","user":{"login":"nickaleks","id":14168731,"avatar_url":"https://avatars0.githubusercontent.com/u/14168731?v=4","gravatar_id":"","url":"https://api.github.com/users/nickaleks","html_url":"https://github.com/nickaleks","followers_url":"https://api.github.com/users/nickaleks/followers","following_url":"https://api.github.com/users/nickaleks/following{/other_user}","gists_url":"https://api.github.com/users/nickaleks/gists{/gist_id}","starred_url":"https://api.github.com/users/nickaleks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nickaleks/subscriptions","organizations_url":"https://api.github.com/users/nickaleks/orgs","repos_url":"https://api.github.com/users/nickaleks/repos","events_url":"https://api.github.com/users/nickaleks/events{/privacy}","received_events_url":"https://api.github.com/users/nickaleks/received_events","type":"User","site_admin":false},"body":"\r\n\r\n### Description of the Change\r\nThis change is one of the several changes to provide better error messages to end users and developers. It does so by introducing Result class to PostgresWsvCommand, which allows us to specify what exactly went wrong during execution of the command.\r\n\r\n\r\n### Benefits\r\n1. Better error messages, in case any Postgres command fails\r\n2. Cleaner code in command_executor\r\n\r\n### Possible Drawbacks \r\n\r\n1. Queries still return optional, so code is inconsistent.\r\n2. Increased size of the postgres_wsv_command\r\n3. More tests need to be added to verify error messages\r\n<!-- What are the possible side-effects or negative impacts of the code change? -->\r\n<!-- If no drawbacks, explicitly mention this (write None) -->","created_at":"2018-02-02T16:36:08Z","updated_at":"2018-02-05T19:57:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ee12f68a839f72ccd4e64fcbb1a56f83d93b08f4","assignee":null,"assignees":[],"requested_reviewers":[{"login":"muratovv","id":7502801,"avatar_url":"https://avatars2.githubusercontent.com/u/7502801?v=4","gravatar_id":"","url":"https://api.github.com/users/muratovv","html_url":"https://github.com/muratovv","followers_url":"https://api.github.com/users/muratovv/followers","following_url":"https://api.github.com/users/muratovv/following{/other_user}","gists_url":"https://api.github.com/users/muratovv/gists{/gist_id}","starred_url":"https://api.github.com/users/muratovv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/muratovv/subscriptions","organizations_url":"https://api.github.com/users/muratovv/orgs","repos_url":"https://api.github.com/users/muratovv/repos","events_url":"https://api.github.com/users/muratovv/events{/privacy}","received_events_url":"https://api.github.com/users/muratovv/received_events","type":"User","site_admin":false}],"requested_teams":[],"milestone":null,"commits_url":"https://api.github.com/repos/hyperledger/iroha/pulls/940/commits","review_comments_url":"https://api.github.com/repos/hyperledger/iroha/pulls/940/comments","review_comment_url":"https://api.github.com/repos/hyperledger/iroha/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hyperledger/iroha/issues/940/comments","statuses_url":"https://api.github.com/repos/hyperledger/iroha/statuses/9d3da24cac835821e97937d6de3f26feda6028f4","head":{"label":"hyperledger:feature/wsv_return_result","ref":"feature/wsv_return_result","sha":"9d3da24cac835821e97937d6de3f26feda6028f4","user":{"login":"hyperledger","id":7657900,"avatar_url":"https://avatars2.githubusercontent.com/u/7657900?v=4","gravatar_id":"","url":"https://api.github.com/users/hyperledger","html_url":"https://github.com/hyperledger","followers_url":"https://api.github.com/users/hyperledger/followers","following_url":"https://api.github.com/users/hyperledger/following{/other_user}","gists_url":"https://api.github.com/users/hyperledger/gists{/gist_id}","starred_url":"https://api.github.com/users/hyperledger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hyperledger/subscriptions","organizations_url":"https://api.github.com/users/hyperledger/orgs","repos_url":"https://api.github.com/users/hyperledger/repos","events_url":"https://api.github.com/users/hyperledger/events{/privacy}","received_events_url":"https://api.github.com/users/hyperledger/received_events","type":"Organization","site_admin":false},"repo":{"id":67340575,"name":"iroha","full_name":"hyperledger/iroha","owner":{"login":"hyperledger","id":7657900,"avatar_url":"https://avatars2.githubusercontent.com/u/7657900?v=4","gravatar_id":"","url":"https://api.github.com/users/hyperledger","html_url":"https://github.com/hyperledger","followers_url":"https://api.github.com/users/hyperledger/followers","following_url":"https://api.github.com/users/hyperledger/following{/other_user}","gists_url":"https://api.github.com/users/hyperledger/gists{/gist_id}","starred_url":"https://api.github.com/users/hyperledger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hyperledger/subscriptions","organizations_url":"https://api.github.com/users/hyperledger/orgs","repos_url":"https://api.github.com/users/hyperledger/repos","events_url":"https://api.github.com/users/hyperledger/events{/privacy}","received_events_url":"https://api.github.com/users/hyperledger/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hyperledger/iroha","description":"Iroha - A simple, decentralized ledger","fork":false,"url":"https://api.github.com/repos/hyperledger/iroha","forks_url":"https://api.github.com/repos/hyperledger/iroha/forks","keys_url":"https://api.github.com/repos/hyperledger/iroha/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hyperledger/iroha/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hyperledger/iroha/teams","hooks_url":"https://api.github.com/repos/hyperledger/iroha/hooks","issue_events_url":"https://api.github.com/repos/hyperledger/iroha/issues/events{/number}","events_url":"https://api.github.com/repos/hyperledger/iroha/events","assignees_url":"https://api.github.com/repos/hyperledger/iroha/assignees{/user}","branches_url":"https://api.github.com/repos/hyperledger/iroha/branches{/branch}","tags_url":"https://api.github.com/repos/hyperledger/iroha/tags","blobs_url":"https://api.github.com/repos/hyperledger/iroha/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hyperledger/iroha/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hyperledger/iroha/git/refs{/sha}","trees_url":"https://api.github.com/repos/hyperledger/iroha/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hyperledger/iroha/statuses/{sha}","languages_url":"https://api.github.com/repos/hyperledger/iroha/languages","stargazers_url":"https://api.github.com/repos/hyperledger/iroha/stargazers","contributors_url":"https://api.github.com/repos/hyperledger/iroha/contributors","subscribers_url":"https://api.github.com/repos/hyperledger/iroha/subscribers","subscription_url":"https://api.github.com/repos/hyperledger/iroha/subscription","commits_url":"https://api.github.com/repos/hyperledger/iroha/commits{/sha}","git_commits_url":"https://api.github.com/repos/hyperledger/iroha/git/commits{/sha}","comments_url":"https://api.github.com/repos/hyperledger/iroha/comments{/number}","issue_comment_url":"https://api.github.com/repos/hyperledger/iroha/issues/comments{/number}","contents_url":"https://api.github.com/repos/hyperledger/iroha/contents/{+path}","compare_url":"https://api.github.com/repos/hyperledger/iroha/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hyperledger/iroha/merges","archive_url":"https://api.github.com/repos/hyperledger/iroha/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hyperledger/iroha/downloads","issues_url":"https://api.github.com/repos/hyperledger/iroha/issues{/number}","pulls_url":"https://api.github.com/repos/hyperledger/iroha/pulls{/number}","milestones_url":"https://api.github.com/repos/hyperledger/iroha/milestones{/number}","notifications_url":"https://api.github.com/repos/hyperledger/iroha/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hyperledger/iroha/labels{/name}","releases_url":"https://api.github.com/repos/hyperledger/iroha/releases{/id}","deployments_url":"https://api.github.com/repos/hyperledger/iroha/deployments","created_at":"2016-09-04T11:17:53Z","updated_at":"2018-02-05T13:03:43Z","pushed_at":"2018-02-05T19:40:56Z","git_url":"git://github.com/hyperledger/iroha.git","ssh_url":"git@github.com:hyperledger/iroha.git","clone_url":"https://github.com/hyperledger/iroha.git","svn_url":"https://github.com/hyperledger/iroha","homepage":"http://iroha.tech","size":44369,"stargazers_count":563,"watchers_count":563,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":192,"mirror_url":null,"archived":false,"open_issues_count":40,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":192,"open_issues":40,"watchers":563,"default_branch":"master"}},"base":{"label":"hyperledger:develop","ref":"develop","sha":"fa82a07983aea9bf8b1bde596ff70ea552d6cdbe","user":{"login":"hyperledger","id":7657900,"avatar_url":"https://avatars2.githubusercontent.com/u/7657900?v=4","gravatar_id":"","url":"https://api.github.com/users/hyperledger","html_url":"https://github.com/hyperledger","followers_url":"https://api.github.com/users/hyperledger/followers","following_url":"https://api.github.com/users/hyperledger/following{/other_user}","gists_url":"https://api.github.com/users/hyperledger/gists{/gist_id}","starred_url":"https://api.github.com/users/hyperledger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hyperledger/subscriptions","organizations_url":"https://api.github.com/users/hyperledger/orgs","repos_url":"https://api.github.com/users/hyperledger/repos","events_url":"https://api.github.com/users/hyperledger/events{/privacy}","received_events_url":"https://api.github.com/users/hyperledger/received_events","type":"Organization","site_admin":false},"repo":{"id":67340575,"name":"iroha","full_name":"hyperledger/iroha","owner":{"login":"hyperledger","id":7657900,"avatar_url":"https://avatars2.githubusercontent.com/u/7657900?v=4","gravatar_id":"","url":"https://api.github.com/users/hyperledger","html_url":"https://github.com/hyperledger","followers_url":"https://api.github.com/users/hyperledger/followers","following_url":"https://api.github.com/users/hyperledger/following{/other_user}","gists_url":"https://api.github.com/users/hyperledger/gists{/gist_id}","starred_url":"https://api.github.com/users/hyperledger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hyperledger/subscriptions","organizations_url":"https://api.github.com/users/hyperledger/orgs","repos_url":"https://api.github.com/users/hyperledger/repos","events_url":"https://api.github.com/users/hyperledger/events{/privacy}","received_events_url":"https://api.github.com/users/hyperledger/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hyperledger/iroha","description":"Iroha - A simple, decentralized ledger","fork":false,"url":"https://api.github.com/repos/hyperledger/iroha","forks_url":"https://api.github.com/repos/hyperledger/iroha/forks","keys_url":"https://api.github.com/repos/hyperledger/iroha/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hyperledger/iroha/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hyperledger/iroha/teams","hooks_url":"https://api.github.com/repos/hyperledger/iroha/hooks","issue_events_url":"https://api.github.com/repos/hyperledger/iroha/issues/events{/number}","events_url":"https://api.github.com/repos/hyperledger/iroha/events","assignees_url":"https://api.github.com/repos/hyperledger/iroha/assignees{/user}","branches_url":"https://api.github.com/repos/hyperledger/iroha/branches{/branch}","tags_url":"https://api.github.com/repos/hyperledger/iroha/tags","blobs_url":"https://api.github.com/repos/hyperledger/iroha/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hyperledger/iroha/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hyperledger/iroha/git/refs{/sha}","trees_url":"https://api.github.com/repos/hyperledger/iroha/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hyperledger/iroha/statuses/{sha}","languages_url":"https://api.github.com/repos/hyperledger/iroha/languages","stargazers_url":"https://api.github.com/repos/hyperledger/iroha/stargazers","contributors_url":"https://api.github.com/repos/hyperledger/iroha/contributors","subscribers_url":"https://api.github.com/repos/hyperledger/iroha/subscribers","subscription_url":"https://api.github.com/repos/hyperledger/iroha/subscription","commits_url":"https://api.github.com/repos/hyperledger/iroha/commits{/sha}","git_commits_url":"https://api.github.com/repos/hyperledger/iroha/git/commits{/sha}","comments_url":"https://api.github.com/repos/hyperledger/iroha/comments{/number}","issue_comment_url":"https://api.github.com/repos/hyperledger/iroha/issues/comments{/number}","contents_url":"https://api.github.com/repos/hyperledger/iroha/contents/{+path}","compare_url":"https://api.github.com/repos/hyperledger/iroha/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hyperledger/iroha/merges","archive_url":"https://api.github.com/repos/hyperledger/iroha/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hyperledger/iroha/downloads","issues_url":"https://api.github.com/repos/hyperledger/iroha/issues{/number}","pulls_url":"https://api.github.com/repos/hyperledger/iroha/pulls{/number}","milestones_url":"https://api.github.com/repos/hyperledger/iroha/milestones{/number}","notifications_url":"https://api.github.com/repos/hyperledger/iroha/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hyperledger/iroha/labels{/name}","releases_url":"https://api.github.com/repos/hyperledger/iroha/releases{/id}","deployments_url":"https://api.github.com/repos/hyperledger/iroha/deployments","created_at":"2016-09-04T11:17:53Z","updated_at":"2018-02-05T13:03:43Z","pushed_at":"2018-02-05T19:40:56Z","git_url":"git://github.com/hyperledger/iroha.git","ssh_url":"git@github.com:hyperledger/iroha.git","clone_url":"https://github.com/hyperledger/iroha.git","svn_url":"https://github.com/hyperledger/iroha","homepage":"http://iroha.tech","size":44369,"stargazers_count":563,"watchers_count":563,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":192,"mirror_url":null,"archived":false,"open_issues_count":40,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":192,"open_issues":40,"watchers":563,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/hyperledger/iroha/pulls/940"},"html":{"href":"https://github.com/hyperledger/iroha/pull/940"},"issue":{"href":"https://api.github.com/repos/hyperledger/iroha/issues/940"},"comments":{"href":"https://api.github.com/repos/hyperledger/iroha/issues/940/comments"},"review_comments":{"href":"https://api.github.com/repos/hyperledger/iroha/pulls/940/comments"},"review_comment":{"href":"https://api.github.com/repos/hyperledger/iroha/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hyperledger/iroha/pulls/940/commits"},"statuses":{"href":"https://api.github.com/repos/hyperledger/iroha/statuses/9d3da24cac835821e97937d6de3f26feda6028f4"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"l4l"}}