{"action":"created","comment":{"url":"https://api.github.com/repos/uber/tchannel/pulls/comments/29965661","id":29965661,"diff_hunk":"@@ -102,51 +141,210 @@ function send(request, endpoint, outHead, outBody, callback) {\n     var self = this;\n \n     assert(typeof endpoint === 'string', 'send requires endpoint');\n-\n-    var argsType = self.spec.getType(endpoint + '_args');\n-    var resultType = self.spec.getType(endpoint + '_result');\n-\n-    var outRes = argsType.toBuffer(outBody);\n-    if (outRes.err) {\n-        callback(outRes.err, null);\n-        return;\n+    assert(typeof request.serviceName === 'string' &&\n+        request.serviceName !== '',\n+        'req.serviceName must be a string');\n+\n+    var stringifyResult = self._stringify({\n+        head: outHead,\n+        body: outBody,\n+        endpoint: endpoint,\n+        direction: 'out.request'\n+    });\n+    if (stringifyResult.err) {\n+        return callback(stringifyResult.err);\n     }\n \n-    var outHeadBuffer = null;\n-    var outBodyBuffer = outRes.value;\n-\n     // Punch as=thrift into the transport headers\n-    request.headers.as = \"thrift\";\n+    request.headers.as = 'thrift';\n \n-    request.send(endpoint, outHeadBuffer, outBodyBuffer, handleResponse);\n+    request.send(\n+        endpoint,\n+        stringifyResult.value.head,\n+        stringifyResult.value.body,\n+        handleResponse\n+    );\n \n     function handleResponse(err, res, arg2, arg3) {\n         if (err) {\n             return callback(err);\n         }\n \n-        var inBodyResult = resultType.fromBuffer(arg3);\n-        if (inBodyResult.err) {\n-            return inBodyResult.toCallback(callback); // TODO WrappedError\n+        var parseResult = self._parse({\n+            head: arg2,\n+            body: arg3,\n+            ok: res.ok,\n+            endpoint: endpoint,\n+            direction: 'in.response'\n+        });\n+\n+        if (parseResult.err) {\n+            return callback(parseResult.err);\n         }\n \n-        var inBody;\n+        var v = parseResult.value;\n+        var resp;\n+\n         if (res.ok) {\n-            inBody = inBodyResult.value.success;\n+            resp = new TChannelThriftResponse(res.ok, v.head, v.body);\n         } else {\n-            inBody = onlyProperty(inBodyResult.value);\n+            resp = new TChannelThriftResponse(\n+                res.ok, v.head, errors.ReconstructedError(v.body)\n+            );\n         }\n \n-        // TODO translate inHeadBuffer into inHead\n-        // var inHeadBuffer = arg2;\n-        var inHead = null;\n+        callback(null, resp);\n+    }\n+};\n+\n+TChannelAsThrift.prototype._parse = function parse(opts) {\n+    var self = this;\n+\n+    var argsName = opts.endpoint + '_args';\n+    var argsType = self.spec.getType(argsName);\n+\n+    var returnName = opts.endpoint + '_result';\n+    var resultType = self.spec.getType(returnName);\n+\n+    var headR = bufrw.fromBufferResult(HeaderRW, opts.head);","path":"node/as/thrift.js","position":248,"original_position":248,"commit_id":"a7f444e29f8fae9fec459377b454413f2b9f3492","original_commit_id":"a7f444e29f8fae9fec459377b454413f2b9f3492","user":{"login":"jcorbin","id":49715,"avatar_url":"https://avatars.githubusercontent.com/u/49715?v=3","gravatar_id":"","url":"https://api.github.com/users/jcorbin","html_url":"https://github.com/jcorbin","followers_url":"https://api.github.com/users/jcorbin/followers","following_url":"https://api.github.com/users/jcorbin/following{/other_user}","gists_url":"https://api.github.com/users/jcorbin/gists{/gist_id}","starred_url":"https://api.github.com/users/jcorbin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcorbin/subscriptions","organizations_url":"https://api.github.com/users/jcorbin/orgs","repos_url":"https://api.github.com/users/jcorbin/repos","events_url":"https://api.github.com/users/jcorbin/events{/privacy}","received_events_url":"https://api.github.com/users/jcorbin/received_events","type":"User","site_admin":false},"body":"`headRes` please...","created_at":"2015-05-08T18:43:40Z","updated_at":"2015-05-08T18:43:40Z","html_url":"https://github.com/uber/tchannel/pull/547#discussion_r29965661","pull_request_url":"https://api.github.com/repos/uber/tchannel/pulls/547","_links":{"self":{"href":"https://api.github.com/repos/uber/tchannel/pulls/comments/29965661"},"html":{"href":"https://github.com/uber/tchannel/pull/547#discussion_r29965661"},"pull_request":{"href":"https://api.github.com/repos/uber/tchannel/pulls/547"}}},"pull_request":{"url":"https://api.github.com/repos/uber/tchannel/pulls/547","id":34973299,"html_url":"https://github.com/uber/tchannel/pull/547","diff_url":"https://github.com/uber/tchannel/pull/547.diff","patch_url":"https://github.com/uber/tchannel/pull/547.patch","issue_url":"https://api.github.com/repos/uber/tchannel/issues/547","number":547,"state":"open","locked":false,"title":"Improving as/thrift with header & error supports","user":{"login":"Raynos","id":479538,"avatar_url":"https://avatars.githubusercontent.com/u/479538?v=3","gravatar_id":"","url":"https://api.github.com/users/Raynos","html_url":"https://github.com/Raynos","followers_url":"https://api.github.com/users/Raynos/followers","following_url":"https://api.github.com/users/Raynos/following{/other_user}","gists_url":"https://api.github.com/users/Raynos/gists{/gist_id}","starred_url":"https://api.github.com/users/Raynos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Raynos/subscriptions","organizations_url":"https://api.github.com/users/Raynos/orgs","repos_url":"https://api.github.com/users/Raynos/repos","events_url":"https://api.github.com/users/Raynos/events{/privacy}","received_events_url":"https://api.github.com/users/Raynos/received_events","type":"User","site_admin":false},"body":"This PR adds a bunch of cleanup to bring the\nas thrift implementation inline with as json\n\n - Implement parsing & serializing of arg2 for as thrift\n - Add logging of serialization errors and logging\n    of parsing warnings to as/thrift\n - Grabs the logger from tchannel\n - Send a bad request with more details for parsing failures\n - Send back an UnexpectedError for errors in the callback\n - Send back an UnexpectedError for response serialization failure\n - Reconstruct an error object from not ok call responses.\n\nr: @jcorbin @kriskowal","created_at":"2015-05-08T01:15:45Z","updated_at":"2015-05-08T18:43:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d4c92bf9bf90ceb9e1f07c588066bdaa4504f5a8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/uber/tchannel/pulls/547/commits","review_comments_url":"https://api.github.com/repos/uber/tchannel/pulls/547/comments","review_comment_url":"https://api.github.com/repos/uber/tchannel/pulls/comments{/number}","comments_url":"https://api.github.com/repos/uber/tchannel/issues/547/comments","statuses_url":"https://api.github.com/repos/uber/tchannel/statuses/a7f444e29f8fae9fec459377b454413f2b9f3492","head":{"label":"uber:as-thrift-logging","ref":"as-thrift-logging","sha":"a7f444e29f8fae9fec459377b454413f2b9f3492","user":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"repo":{"id":28419663,"name":"tchannel","full_name":"uber/tchannel","owner":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/uber/tchannel","description":"network multiplexing and framing protocol for RPC","fork":false,"url":"https://api.github.com/repos/uber/tchannel","forks_url":"https://api.github.com/repos/uber/tchannel/forks","keys_url":"https://api.github.com/repos/uber/tchannel/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uber/tchannel/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uber/tchannel/teams","hooks_url":"https://api.github.com/repos/uber/tchannel/hooks","issue_events_url":"https://api.github.com/repos/uber/tchannel/issues/events{/number}","events_url":"https://api.github.com/repos/uber/tchannel/events","assignees_url":"https://api.github.com/repos/uber/tchannel/assignees{/user}","branches_url":"https://api.github.com/repos/uber/tchannel/branches{/branch}","tags_url":"https://api.github.com/repos/uber/tchannel/tags","blobs_url":"https://api.github.com/repos/uber/tchannel/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uber/tchannel/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uber/tchannel/git/refs{/sha}","trees_url":"https://api.github.com/repos/uber/tchannel/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uber/tchannel/statuses/{sha}","languages_url":"https://api.github.com/repos/uber/tchannel/languages","stargazers_url":"https://api.github.com/repos/uber/tchannel/stargazers","contributors_url":"https://api.github.com/repos/uber/tchannel/contributors","subscribers_url":"https://api.github.com/repos/uber/tchannel/subscribers","subscription_url":"https://api.github.com/repos/uber/tchannel/subscription","commits_url":"https://api.github.com/repos/uber/tchannel/commits{/sha}","git_commits_url":"https://api.github.com/repos/uber/tchannel/git/commits{/sha}","comments_url":"https://api.github.com/repos/uber/tchannel/comments{/number}","issue_comment_url":"https://api.github.com/repos/uber/tchannel/issues/comments{/number}","contents_url":"https://api.github.com/repos/uber/tchannel/contents/{+path}","compare_url":"https://api.github.com/repos/uber/tchannel/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uber/tchannel/merges","archive_url":"https://api.github.com/repos/uber/tchannel/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uber/tchannel/downloads","issues_url":"https://api.github.com/repos/uber/tchannel/issues{/number}","pulls_url":"https://api.github.com/repos/uber/tchannel/pulls{/number}","milestones_url":"https://api.github.com/repos/uber/tchannel/milestones{/number}","notifications_url":"https://api.github.com/repos/uber/tchannel/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uber/tchannel/labels{/name}","releases_url":"https://api.github.com/repos/uber/tchannel/releases{/id}","created_at":"2014-12-23T21:06:57Z","updated_at":"2015-05-08T18:14:11Z","pushed_at":"2015-05-08T18:14:17Z","git_url":"git://github.com/uber/tchannel.git","ssh_url":"git@github.com:uber/tchannel.git","clone_url":"https://github.com/uber/tchannel.git","svn_url":"https://github.com/uber/tchannel","homepage":"","size":16904,"stargazers_count":48,"watchers_count":48,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":77,"forks":3,"open_issues":77,"watchers":48,"default_branch":"master"}},"base":{"label":"uber:master","ref":"master","sha":"560fdc2a5c2cbe0ad4340f9813c0efcb168f9201","user":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"repo":{"id":28419663,"name":"tchannel","full_name":"uber/tchannel","owner":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/uber/tchannel","description":"network multiplexing and framing protocol for RPC","fork":false,"url":"https://api.github.com/repos/uber/tchannel","forks_url":"https://api.github.com/repos/uber/tchannel/forks","keys_url":"https://api.github.com/repos/uber/tchannel/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uber/tchannel/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uber/tchannel/teams","hooks_url":"https://api.github.com/repos/uber/tchannel/hooks","issue_events_url":"https://api.github.com/repos/uber/tchannel/issues/events{/number}","events_url":"https://api.github.com/repos/uber/tchannel/events","assignees_url":"https://api.github.com/repos/uber/tchannel/assignees{/user}","branches_url":"https://api.github.com/repos/uber/tchannel/branches{/branch}","tags_url":"https://api.github.com/repos/uber/tchannel/tags","blobs_url":"https://api.github.com/repos/uber/tchannel/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uber/tchannel/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uber/tchannel/git/refs{/sha}","trees_url":"https://api.github.com/repos/uber/tchannel/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uber/tchannel/statuses/{sha}","languages_url":"https://api.github.com/repos/uber/tchannel/languages","stargazers_url":"https://api.github.com/repos/uber/tchannel/stargazers","contributors_url":"https://api.github.com/repos/uber/tchannel/contributors","subscribers_url":"https://api.github.com/repos/uber/tchannel/subscribers","subscription_url":"https://api.github.com/repos/uber/tchannel/subscription","commits_url":"https://api.github.com/repos/uber/tchannel/commits{/sha}","git_commits_url":"https://api.github.com/repos/uber/tchannel/git/commits{/sha}","comments_url":"https://api.github.com/repos/uber/tchannel/comments{/number}","issue_comment_url":"https://api.github.com/repos/uber/tchannel/issues/comments{/number}","contents_url":"https://api.github.com/repos/uber/tchannel/contents/{+path}","compare_url":"https://api.github.com/repos/uber/tchannel/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uber/tchannel/merges","archive_url":"https://api.github.com/repos/uber/tchannel/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uber/tchannel/downloads","issues_url":"https://api.github.com/repos/uber/tchannel/issues{/number}","pulls_url":"https://api.github.com/repos/uber/tchannel/pulls{/number}","milestones_url":"https://api.github.com/repos/uber/tchannel/milestones{/number}","notifications_url":"https://api.github.com/repos/uber/tchannel/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uber/tchannel/labels{/name}","releases_url":"https://api.github.com/repos/uber/tchannel/releases{/id}","created_at":"2014-12-23T21:06:57Z","updated_at":"2015-05-08T18:14:11Z","pushed_at":"2015-05-08T18:14:17Z","git_url":"git://github.com/uber/tchannel.git","ssh_url":"git@github.com:uber/tchannel.git","clone_url":"https://github.com/uber/tchannel.git","svn_url":"https://github.com/uber/tchannel","homepage":"","size":16904,"stargazers_count":48,"watchers_count":48,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":77,"forks":3,"open_issues":77,"watchers":48,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/uber/tchannel/pulls/547"},"html":{"href":"https://github.com/uber/tchannel/pull/547"},"issue":{"href":"https://api.github.com/repos/uber/tchannel/issues/547"},"comments":{"href":"https://api.github.com/repos/uber/tchannel/issues/547/comments"},"review_comments":{"href":"https://api.github.com/repos/uber/tchannel/pulls/547/comments"},"review_comment":{"href":"https://api.github.com/repos/uber/tchannel/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/uber/tchannel/pulls/547/commits"},"statuses":{"href":"https://api.github.com/repos/uber/tchannel/statuses/a7f444e29f8fae9fec459377b454413f2b9f3492"}}}}