Liquid and ‘invalid byte sequence in US-ASCII’

FreeBSD, Jekyll, and Liquid sitting in a tree.

The Situation

You’ve built an awesome Jekyll site, and now you’re setting up a FreeBSD server that will also automatically compile and publish your site when you push up to your repo’s master branch. You’re all:

groovin

And then, out of nowhere, you get:

Liquid Exception: invalid byte sequence in US-ASCII in index.html

Your mood changes.

wtf

You hit the Google, looking for some answers. Some links seem promising, but nothing really concrete. No obvious answer in spot #1.

The Answer

The answer lies with your shell’s LANG setting. The FreeBSD way to set this is in /etc/login.conf. On a stock install, you’ll have something like this:

default:\
  :passwd_format=md5:\
  :copyright=/etc/COPYRIGHT:\
  :welcome=/etc/motd:\

  *snip, snip...*

  :priority=0:\
  :ignoretime@:\
  :umask=022:

Simply set lang to your appropriate UTF-8 setting (probably en_US.UTF-8):

default:\
  :passwd_format=md5:\
  :copyright=/etc/COPYRIGHT:\
  :welcome=/etc/motd:\

  *snip, snip...*

  :priority=0:\
  :ignoretime@:\
  :umask=022:\
  :lang=en_US.UTF-8:

Any changes to /etc/login.conf need to reloaded by running (with root privileges):

cap_mkdb /etc/login.conf

Log into your FreeBSD environment again, and give it another whirl.

all good