opscode/chef-dk — pull request #214 by danielsdeleo (2014-10-30 21:23:19+00:00)
Title: Improve Debug for Policyfile Commands

While investigating #208 I found that the debugging info wasn't sufficient to understand the cause of the issue. This patch adds extensive debugging for HTTP request failures, it looks like this (when the debug switch, `-D` is enabled):

```
Error: HTTP 400 Bad Request: Field 'name' invalid
Reason: Net::HTTPServerException

--- REQUEST DATA ----
PUT /organizations/chef-oss-dev/cookbooks/policyfile_demo/67638399371010690.23642238397896298.25512023620585
content-type: application/json
accept: application/json
accept-encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
x-ops-sign: algorithm=sha1;version=1.0;
x-ops-userid: kallistec
x-ops-timestamp: 2014-10-29T22:27:47Z
x-ops-content-hash: 8uVW3h21ZeI4roaxsLr3C8OkE4A=
x-ops-authorization-1: ltDHjhNJhRg51NbUPWcLZ7p2P79RP+4PQRQn7VKPFPXWUP6HVTNm8k1Zwbph
x-ops-authorization-2: FbnC+K3OR0CAq8hzvlqDeoQtKQQdZ890xUze/w1rakrk8cB+0k3o5+swdyaS
x-ops-authorization-3: WJTdD7r/Usg2P8fkMloms2iW7auKAO1RO3MRI3UqKk/0VK7zxBvPqFd7v6Py
x-ops-authorization-4: qD3uyDBGxFLo0dZQk4HRJCAAFKXWoAJkmxo9o5sH6PYcYvrjmxzSBMVQMP52
x-ops-authorization-5: M3NhpRntrS3ipsAZKpTJud0xXGl7HuW5XpROcy5ZCyTMtwVeR3E4duclRSiB
x-ops-authorization-6: nXEcNtcPjq1VFGCVjvgyNOZwEPIvMEkqm6yOVS81Og==
host: api.opscode.com:443
content-length: 1130
x-chef-version: 12.0.0.alpha.2
user-agent: Chef Knife/12.0.0.alpha.2 (ruby-2.1.2-p95; ohai-7.6.0.rc.0; x86_64-darwin13.0; +http://opscode.com)
connection: close

{"recipes":[{"name":"default.rb","path":"recipes/default.rb","checksum":"d95a0c536f8db49721ab100b9a5a8fc9","specificity":"default"}],"definitions":[],"libraries":[],"attributes":[],"files":[],"templates":[],"resources":[],"providers":[],"root_files":[{"name":"chefignore","path":"chefignore","checksum":"03485640b005eb1083c76518764053dd","specificity":"default"},{"name":"metadata.rb","path":"metadata.rb","checksum":"9696a5e086c7fa77052f3c2016315050","specificity":"default"}],"cookbook_name":"policyfile_demo","metadata":{"name":"policyfile_demo","description":"Installs/Configures ","long_description":"Installs/Configures ","maintainer":"","maintainer_email":"","license":"","platforms":{},"dependencies":{},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{"policyfile_demo":">= 0.0.0"},"replacing":{},"attributes":{},"groupings":{},"recipes":{"policyfile_demo":""},"version":"67638399371010690.23642238397896298.25512023620585"},"version":"67638399371010690.23642238397896298.25512023620585","name":"policyfile_demo-0.1.0","frozen?":true,"chef_type":"cookbook_version","json_class":"Chef::CookbookVersion"}

--- RESPONSE DATA ---
400 Bad Request
server: ngx_openresty
date: Wed, 29 Oct 2014 22:27:47 GMT
content-length: 34
connection: close
x-ops-api-info: flavor=hec;version=12.0.0;oc_erchef=0.29.0

{"error":["Field 'name' invalid"]}
```

Without the debug switch, it is still a bit more informative than before:

```
Error: Failed to upload policy to policy group demo
Reason: (Net::HTTPServerException) HTTP 400 Bad Request: Field 'name' invalid
```

@opscode/client-engineers