berkshelf/ridley

Problem with non ascii characters

Paxa opened this issue · 4 comments

Paxa commented

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))

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

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

syhe commented

@reset Any plans to fix this?

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

fixed in berks here:

berkshelf/berkshelf#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.