Skip to content

Commit

Permalink
user: Catch zlib errors to provide a friendlier error message
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberShadow committed Jun 27, 2014
1 parent 947c426 commit 6464275
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions user.d
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,24 @@ final:
{
// Temporary hack to catch Phobos bug
ubyte[] zcode;

enum advice = "Try clearing your browser's cookies. Create an account to avoid repeated incidents.";

try
zcode = Base64.decode(b64);
catch
{
import std.file;
write("bad-base64.txt", b64);
throw new Exception("Malformed Base64 in read post history cookie. Try clearing your cookies.");
import std.file; write("bad-base64.txt", b64);
throw new Exception("Malformed Base64 in read post history cookie. " ~ advice);
}

try
readPosts = [uncompress(Data(zcode))].ptr;
catch (ZlibException e)
{
import std.file; write("bad-zlib.z", zcode);
throw new Exception("Malformed deflated data in read post history cookie (" ~ e.msg ~ "). " ~ advice);
}
readPosts = [uncompress(Data(zcode))].ptr;
}
else
readPosts = new Data();
Expand Down

0 comments on commit 6464275

Please sign in to comment.