berkshelf / ridley

A reliable Chef API client with a clean syntax
Other
231 stars 85 forks source link

Problem with non ascii characters #305

Closed Paxa closed 7 years ago

Paxa commented 9 years ago

I got this error when I run berks install

/Users/me/.rvm/gems/ruby-2.1.5/gems/json-1.8.2/lib/json/common.rb:155:in `encode': "\xE2" on US-ASCII (Encoding::InvalidByteSequenceError)
    from /Users/pavel/.rvm/gems/ruby-2.1.5/gems/json-1.8.2/lib/json/common.rb:155:in `initialize'
    from /Users/pavel/.rvm/gems/ruby-2.1.5/gems/json-1.8.2/lib/json/common.rb:155:in `new'
    from /Users/pavel/.rvm/gems/ruby-2.1.5/gems/json-1.8.2/lib/json/common.rb:155:in `parse'
    from /Users/pavel/.rvm/gems/ruby-2.1.5/gems/ridley-4.1.2/lib/ridley/chef/cookbook/metadata.rb:473:in `from_json'
    from /Users/pavel/.rvm/gems/ruby-2.1.5/gems/ridley-4.1.2/lib/ridley/chef/cookbook/metadata.rb:29:in `from_json'
    from /Users/pavel/.rvm/gems/ruby-2.1.5/gems/ridley-4.1.2/lib/ridley/chef/cookbook.rb:37:in `from_path'
    from /Users/pavel/.rvm/gems/ruby-2.1.5/gems/berkshelf-3.2.3/lib/berkshelf/cached_cookbook.rb:15:in `from_store_path'

Solution is:

# lib/ridley/chef/cookbook.rb
# line 37

metadata = Metadata.from_json(File.read(file))
# replace with
metadata = Metadata.from_json(File.open(file, 'r:utf-8', &:read))
josacar commented 9 years ago

@reset Any plans to fix this? the solution is dead simple and I think there are no cookbooks using utf-16 or utf-32.

josacar commented 9 years ago

This happens when LC_ALL, LANGUAGE or LANG environment variables are not declared.

syhe commented 8 years ago

@reset Any plans to fix this?

This is especially relevant in stripped down environments that might not have locales configured, like some Docker containers.

lamont-granquist commented 7 years ago

fixed in berks here:

https://github.com/berkshelf/berkshelf/pull/1588

this is not an issue that ridley should handle. the user has failed to set a locale which should be entirely user error. failing that though (and because of things like the way Ubuntu 14.04 upstart fails to read the system locale and starts daemons without any localization and other brain damage) the application should setup an encoding. in no way should this be the responsibility of the rest client library.