How I Fixed 'Invalid Byte Sequence in US-ASCII' Exception With Octopress (and Vagrant)

I don’t know if you noticed, but Octopress 2 preview is slow as hell on Virtual Box. I wanted to try using Docker instead. So a few weeks ago, I started to upgrade my Vagrant, Virtual Box and Docker stack …

Hell loose !

A naughty dog with a banner "I'm in upgrade hell"

I know all open source software needs to be kept up to date at all time, but it’s not that easy. Especialy when the versions in the Ubuntu repostiories are really old and you had to install them manually. Anyway, after a bit of tedious work, I finally got to the point where my Octopress blog was running on a brand new stack. And I got this error :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
vagrant@239c4077ae16:/vagrant$bundle exec rake generate
## Generating Site with Jekyll
unchanged sass/screen.scss
/vagrant/vendor/bundle/gems/liquid-2.3.0/lib/liquid/htmltags.rb:44: warning: duplicated key at line 47 ignored: "index0"
Configuration from /vagrant/_config.yml
Building site: source -> public
YAML Exception reading index.markdown: invalid byte sequence in US-ASCII
/vagrant/plugins/backtick_code_block.rb:13:in `gsub': invalid byte sequence in US-ASCII (ArgumentError)
  from /vagrant/plugins/backtick_code_block.rb:13:in `render_code_block'
  from /vagrant/plugins/octopress_filters.rb:12:in `pre_filter'
  from /vagrant/plugins/octopress_filters.rb:28:in `pre_render'
  from /vagrant/plugins/post_filters.rb:112:in `block in pre_render'
  from /vagrant/plugins/post_filters.rb:111:in `each'
  from /vagrant/plugins/post_filters.rb:111:in `pre_render'
  from /vagrant/plugins/post_filters.rb:166:in `do_layout'
  from /vagrant/vendor/bundle/gems/jekyll-0.12.1/lib/jekyll/page.rb:100:in `render'
  from /vagrant/vendor/bundle/gems/jekyll-0.12.1/lib/jekyll/site.rb:204:in `block in render'
  from /vagrant/vendor/bundle/gems/jekyll-0.12.1/lib/jekyll/site.rb:203:in `each'
  from /vagrant/vendor/bundle/gems/jekyll-0.12.1/lib/jekyll/site.rb:203:in `render'
  from /vagrant/vendor/bundle/gems/jekyll-0.12.1/lib/jekyll/site.rb:41:in `process'
  from /vagrant/vendor/bundle/gems/jekyll-0.12.1/bin/jekyll:264:in `<top (required)>'
  from /vagrant/vendor/bundle/bin/jekyll:23:in `load'
  from /vagrant/vendor/bundle/bin/jekyll:23:in `<main>'

After some searching on the internet, I found this post by Alex Zeitler that made me figure out that locales were not set correctly by default on my vm. I just needed to set this once and for all in my Vagrantfile

1
2
3
4
5
6
7
8
9
10
config.vm.provision "shell", privileged: false, inline: <<-SHELL
  if [ -z "$LANG" ]; then
    echo "Setting LANG to us UTF8"
    echo 'export LANG=en_US.UTF-8' >> ~/.bashrc
  fi
  if [ -z "$LC_ALL" ]; then
    echo "Setting LC_ALL to us UTF8"
    echo 'export LC_ALL=en_US.UTF-8' >> ~/.bashrc
  fi
SHELL

After reprovisioning my box, generate and preview were working as expected !

:–( Now I’ve got a pygement-ruby issue to deal with, I guess I’ll be back on the subject soon …

Comments