Friday, March 18, 2011

Invalid byte sequence in UTF-8

If you ever encountered this error when you are running your Sproutcore application:

ArgumentError at /yourapp
invalid byte sequence in UTF-8

you should check your comments in files for characters like © that are not valid UTF-8.

http://en.wikipedia.org/wiki/UTF-8#Codepage_layout

If your preferred editor has a setting regarding file encoding, you should set that on UTF-8 and the problems are solved.


That was my piece of code.

2 comments:

  1. It's very common for people to copy and paste from older documents from older Microsoft products that use Windows Code Page 1252 (aka CP-1252), such as some versions of Microsoft Word. This Western encoding has the 'smart quote' characters, the copyright symbol, and a bunch of other code points stuffed into the space between 128-160. These are invalid in UTF-8, but it is trivial to convert to UTF-8 on a system that has GNU iconv installed (Linux, Mac OS, Cygwin and MSYS on Windows all have it):

    iconv -f cp1252 -t UTF-8 < sample-fail.txt > sample-good.txt

    ReplyDelete
  2. OMG you rock, I have been searching for this error for hours and finally found the solution, I generated the code with the sc-init and it puts a comment with an © sign on it and it throws that error, thanks a lot =)

    ReplyDelete