Error in json_compat when doing a cookbook upload


#1

does anyone get this error while doing a knife cookbook upload ..

1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:43:in
rescue in block in deep_const_get': can't get const Chef::Sandbox: uninitialized constant Chef::Sandbox (ArgumentError) from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:40:inblock in deep_const_get’
from
/Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:35:in
each' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:35:ininject’
from
/Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:35:in
deep_const_get' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:148:inparse’
from
/Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:148:in
parse' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/json_compat.rb:41:infrom_json’
from
/Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/rest.rb:217:in
block in raw_http_request' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/rest.rb:317:inretriable_rest_request’
from
/Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/rest.rb:201:in
raw_http_request' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/rest.rb:195:inapi_request’
from
/Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/rest.rb:162:in
put' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/cookbook_uploader.rb:99:inupload_cookbooks’
from
/Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/knife/cookbook_upload.rb:230:in
`upload’

making the following changes in rest.rb (line 217) fixed it.
if response[‘content-type’] =~ /json/

  • Chef::JSONCompat.from_json(response_body.chomp, create_additions: false)*
    else

but I’m wondering if there is something else that I should be doing than
this fix…


#2

On Tuesday, December 4, 2012 at 3:21 AM, Kishore S Kumar wrote:

does anyone get this error while doing a knife cookbook upload ..

1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:43:in rescue in block in deep_const_get': can't get const Chef::Sandbox: uninitialized constant Chef::Sandbox (ArgumentError) from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:40:inblock in deep_const_get’
from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:35:in each' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:35:ininject’
from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:35:in deep_const_get' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:148:inparse’
from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:148:in parse' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/json_compat.rb:41:infrom_json’
from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/rest.rb:217:in block in raw_http_request' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/rest.rb:317:inretriable_rest_request’
from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/rest.rb:201:in raw_http_request' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/rest.rb:195:inapi_request’
from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/rest.rb:162:in put' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/cookbook_uploader.rb:99:inupload_cookbooks’
from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/knife/cookbook_upload.rb:230:in `upload’

making the following changes in rest.rb (line 217) fixed it.
if response[‘content-type’] =~ /json/
Chef::JSONCompat.from_json(response_body.chomp, create_additions: false)
else

but I’m wondering if there is something else that I should be doing than this fix…

Looks like you’re building from master? We recently fixed this, so try pulling and rebuilding the gem.

Chef unfortunately still relies on magical class inflation via json_class in quite a few places, so setting create_additions to false would break things elsewhere. We ended up fixing this particular issue by adding a dummy Sandbox class, which was the least ugly solution. Getting rid of json_class is something we’d like to do but just haven’t had time for yet.


Daniel DeLeo


#3

Yes I was building master…!! However did the issue exist in previous
releases and you did the same fix as this or was there a change in the way
json parsing in done in 11.
On Dec 4, 2012 10:33 PM, “Daniel DeLeo” dan@kallistec.com wrote:

On Tuesday, December 4, 2012 at 3:21 AM, Kishore S Kumar wrote:

does anyone get this error while doing a knife cookbook upload ..

1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:43:in
rescue in block in deep_const_get': can't get const Chef::Sandbox: uninitialized constant Chef::Sandbox (ArgumentError) from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:40:inblock in deep_const_get’
from
/Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:35:in
each' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:35:ininject’
from
/Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:35:in
deep_const_get' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:148:inparse’
from
/Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:148:in
parse' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/json_compat.rb:41:infrom_json’
from
/Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/rest.rb:217:in
block in raw_http_request' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/rest.rb:317:inretriable_rest_request’
from
/Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/rest.rb:201:in
raw_http_request' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/rest.rb:195:inapi_request’
from
/Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/rest.rb:162:in
put' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/cookbook_uploader.rb:99:inupload_cookbooks’
from
/Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/knife/cookbook_upload.rb:230:in
`upload’

making the following changes in rest.rb (line 217) fixed it.
if response[‘content-type’] =~ /json/

  • Chef::JSONCompat.from_json(response_body.chomp, create_additions: false
    )*
    else

but I’m wondering if there is something else that I should be doing than
this fix…

Looks like you’re building from master? We recently fixed this, so try
pulling and rebuilding the gem.

Chef unfortunately still relies on magical class inflation via json_class
in quite a few places, so setting create_additions to false would break
things elsewhere. We ended up fixing this particular issue by adding a
dummy Sandbox class, which was the least ugly solution. Getting rid of
json_class is something we’d like to do but just haven’t had time for yet.


Daniel DeLeo


#4

On Tuesday, December 4, 2012 at 6:29 PM, Kishore S Kumar wrote:

Yes I was building master…!! However did the issue exist in previous releases and you did the same fix as this or was there a change in the way json parsing in done in 11.
On Dec 4, 2012 10:33 PM, “Daniel DeLeo” <dan@kallistec.com (mailto:dan@kallistec.com)> wrote:

We just recently removed all chef-server code from the Chef repository (and moved the remaining relevant code for chef-expander and chef-solr into separate repos). As part of this patch, we removed the Chef::Sandbox class. Unfortunately, Chef 10.x servers (and Opscode Hosted Chef) return JSON with a json_class of Chef::Sandbox from one of the API calls in cookbook upload.

So there’s no change to how we parse JSON, it’s just that we’d removed the class definition of Chef::Sandbox, not realizing it would be referenced when uploading cookbooks.


Daniel DeLeo

On Tuesday, December 4, 2012 at 3:21 AM, Kishore S Kumar wrote:

does anyone get this error while doing a knife cookbook upload ..

1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:43:in rescue in block in deep_const_get': can't get const Chef::Sandbox: uninitialized constant Chef::Sandbox (ArgumentError) from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:40:inblock in deep_const_get’
from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:35:in each' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:35:ininject’
from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:35:in deep_const_get' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:148:inparse’
from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:148:in parse' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/json_compat.rb:41:infrom_json’
from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/rest.rb:217:in block in raw_http_request' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/rest.rb:317:inretriable_rest_request’
from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/rest.rb:201:in raw_http_request' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/rest.rb:195:inapi_request’
from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/rest.rb:162:in put' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/cookbook_uploader.rb:99:inupload_cookbooks’
from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/knife/cookbook_upload.rb:230:in `upload’

making the following changes in rest.rb (line 217) fixed it.
if response[‘content-type’] =~ /json/
Chef::JSONCompat.from_json(response_body.chomp, create_additions: false)
else

but I’m wondering if there is something else that I should be doing than this fix…

Looks like you’re building from master? We recently fixed this, so try pulling and rebuilding the gem.

Chef unfortunately still relies on magical class inflation via json_class in quite a few places, so setting create_additions to false would break things elsewhere. We ended up fixing this particular issue by adding a dummy Sandbox class, which was the least ugly solution. Getting rid of json_class is something we’d like to do but just haven’t had time for yet.


Daniel DeLeo


#5

Thanks for reply… One last question
Is there a plan to remove json_class from all the jsons chef uses? Or would
newer chef servers don’t return a json with chef::sandbox for json_class?
On Dec 5, 2012 8:27 AM, “Daniel DeLeo” dan@kallistec.com wrote:

On Tuesday, December 4, 2012 at 6:29 PM, Kishore S Kumar wrote:

Yes I was building master…!! However did the issue exist in previous
releases and you did the same fix as this or was there a change in the way
json parsing in done in 11.
On Dec 4, 2012 10:33 PM, “Daniel DeLeo” dan@kallistec.com wrote:

We just recently removed all chef-server code from the Chef repository
(and moved the remaining relevant code for chef-expander and chef-solr into
separate repos). As part of this patch, we removed the Chef::Sandbox class.
Unfortunately, Chef 10.x servers (and Opscode Hosted Chef) return JSON with
a json_class of Chef::Sandbox from one of the API calls in cookbook upload.

So there’s no change to how we parse JSON, it’s just that we’d removed the
class definition of Chef::Sandbox, not realizing it would be referenced
when uploading cookbooks.


Daniel DeLeo

On Tuesday, December 4, 2012 at 3:21 AM, Kishore S Kumar wrote:

does anyone get this error while doing a knife cookbook upload ..

1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:43:in
rescue in block in deep_const_get': can't get const Chef::Sandbox: uninitialized constant Chef::Sandbox (ArgumentError) from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:40:inblock in deep_const_get’
from
/Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:35:in
each' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:35:ininject’
from
/Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:35:in
deep_const_get' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:148:inparse’
from
/Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/json-1.6.1/lib/json/common.rb:148:in
parse' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/json_compat.rb:41:infrom_json’
from
/Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/rest.rb:217:in
block in raw_http_request' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/rest.rb:317:inretriable_rest_request’
from
/Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/rest.rb:201:in
raw_http_request' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/rest.rb:195:inapi_request’
from
/Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/rest.rb:162:in
put' from /Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/cookbook_uploader.rb:99:inupload_cookbooks’
from
/Users/kishorek/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/chef-11.0.0.alpha/lib/chef/knife/cookbook_upload.rb:230:in
`upload’

making the following changes in rest.rb (line 217) fixed it.
if response[‘content-type’] =~ /json/

  • Chef::JSONCompat.from_json(response_body.chomp, create_additions: false
    )*
    else

but I’m wondering if there is something else that I should be doing than
this fix…

Looks like you’re building from master? We recently fixed this, so try
pulling and rebuilding the gem.

Chef unfortunately still relies on magical class inflation via json_class
in quite a few places, so setting create_additions to false would break
things elsewhere. We ended up fixing this particular issue by adding a
dummy Sandbox class, which was the least ugly solution. Getting rid of
json_class is something we’d like to do but just haven’t had time for yet.


Daniel DeLeo


#6

On Dec 4, 2012, at 7:40 PM, Kishore S Kumar wrote:
Thanks for reply… One last question

Is there a plan to remove json_class from all the jsons chef uses? Or would newer chef servers don’t return a json with chef::sandbox for json_class?

Removing the ‘json_class’ key from JSON responses sent by Chef Server and altering the Chef code base to use a more explicit mechanism of parsing JSON data into Chef objects is something that the team at Opscode would like to see happen.

We don’t, at present, have an explicit timeline for when these changes would occur. The first step would be making changes to the client code to not rely on the json_class auto-inflation. Then in a major release, the server could stop emitting those keys.

  • seth

#7

Got it… !! :slight_smile: thanks for response
On Dec 5, 2012 9:26 AM, “Seth Falcon” seth@opscode.com wrote:

On Dec 4, 2012, at 7:40 PM, Kishore S Kumar wrote:
Thanks for reply… One last question

Is there a plan to remove json_class from all the jsons chef uses? Or
would newer chef servers don’t return a json with chef::sandbox for
json_class?

Removing the ‘json_class’ key from JSON responses sent by Chef Server and
altering the Chef code base to use a more explicit mechanism of parsing
JSON data into Chef objects is something that the team at Opscode would
like to see happen.

We don’t, at present, have an explicit timeline for when these changes
would occur. The first step would be making changes to the client code to
not rely on the json_class auto-inflation. Then in a major release, the
server could stop emitting those keys.

  • seth