defunkt/resque — Issue #507: Getting `Resque::Helpers::DecodeException` on the failed page on the Web UI
Author: myronmarston
Created: 2012-02-08 17:37:39+00:00
State: open

This has happened to us a couple of times now. Some of the libraries we depend on raise exceptions in jobs that may include invalid UTF-8 bytes in the error message (generally this is because it received an unexpected HTTP response, and it includes the response body in the error message for troubleshooting).

When the job fails, it (surprisingly) manages to encode the error message to JSON and save it to redis w/o an error; however, when we visit the failed page, on the Web UI, it blows up when it tries to decode the error. It's probably a bug in the JSON library (yajl, in our case) that it allows the invalid bytes to be encoded but not decoded...but I also think it's worth doing something about it in resque so we can continue to use our failed page.

I've hacked together a monkey patch in our project that sanitizes the error message before the `Resque::Failure::Redis` back end saves it to redis. @defunkt: would you be willing to accept a pull request with the same fix directly in resque? It'd be nice to get it upstream.

The one thing I'm unsure of is how best to handle this on 1.8. We're on 1.9, and thus can use the nice 1.9 string encoding APIs to sanitize the string. On 1.8, I guess iconv would have to be used? Or is there a better approach?