67

Wow, what a fucking mess this sunday was.
My boss wrote me an email that one route of a RESTful API we wrote for a customer was not working anymore and puking back a status 500 with some error mentioning invalid UTF-8 characters.
Not one single person has had touched nor changed the code on production in some 6 months, so what the fuck could it be?

Phpunit did not give any errors (running only locally), the code had no syntax errors and the DB dump did not contain any invalid bytes (tested with a hex editor).

WHAT THE FUCK?!

OK so I started to comment out lines (all tested directly on production of course) until the error vanished.

Guess what was the culprit?
.
.
.
.
.
.
In the code (PHP) we used strftime(...) to get nice time strings. Of course we set the correct locale on the server, thus having months and days formatted in German.
So, in Geman there is this one mysterious month called "März" which contains an umlaut character.
Calling strftime generated the date with März in it, but the server locale was de_CH.iso-8859-1 and not fucking de_CH.utf8, so the "ä" was returned as 0xE4 instead of 0xC3A4 (valid UTF-8), which json_encode(...) did not want to swallow but instead threw an exception.

Comments
  • 19
    Good catch, I think this is a good example of an error that is minuscule but can even throw off rail even a good written code.
  • 5
    This story reminds me a problem we had on production as well.

    We used to import Facebook page reporting analytics and user interactions. After almost 2 years without touching the code it just broke.

    There were some user interactions that were not being saved and that influenced Facebook page statistics in our internal dashboard.

    What was happening? The guy who architected the table used latin1_swedish_ci as the collation, and suddenly people started using Emojis. Guess what, posts not inserted.

    Changing it to utf8_general_ci fixed it.

    Solved ¯\_(ツ)_/¯
  • 4
    Luckily even big companies have encoding issues *cough* apple *cough*, so you shouldn't worry too much :)
  • 2
    @AlexDeLarge infuriatibug*

    FTFY, hehe
  • 3
    Good lord, what a nightmare. Someone buy this person a beer!
  • 0
    @Bitwise No worries, mate. Good that you found a more sane Date function! 😉
  • 2
    March 😑 #WeHateMarch
  • 1
    And this is why I FUCKING HATE the fact that we still have to suffer with different encodings.
Add Comment