Wednesday, July 10, 2013

Sending Error Responses in Poet

I'm playing around with Poet, a new Mason-based web framework in Perl.

You can read more about it here:

One thing seems under-documented: how do you deal with error pages?

Well, you probably noticed there is a directory called "static/errors" and in it there are things like "404.html" and so on. So far so good: these are what they appear to be.

But how do you trigger one?

The documentation for Poet::Mason shows a very useful method:

abort (status)
clear_and_abort (status)
    These methods are overridden to set the response status
    before aborting, if status is provided. e.g. to send back
    a FORBIDDEN result:


    This is equivalent to


    If a status is not provided, the methods work just as

Great, so all we need is:

    # you can't see me!

and... boom! You are served the standard 404 page from your "static/errors" directory.

But what about a 400 BAD REQUEST, which is more likely to be needed in the first place? Just changing that status code to 400 gives us... only the status code in the response headers, and a blank page. At least that much worked.

But a quick look at "static/errors" shows there is no "400.html" -- and all we need to do is drop one in, right? Wrong. Or half-wrong anyway: we do need to create that file, but just creating it isn't enough.

It turns out this is controlled in "bin/app.psgi" (around line 20). The command:

enable "ErrorDocument",
    map { $_ => $poet->static_path("errors/$_.html") }
    qw(401 403 404 500);

So now we just add a "400" to that list and restart the server, right?


Hope that helps.

Tuesday, June 25, 2013

RuPy Conference October 11-13, 2013

Do you do Ruby?

And/or Python?

And/or open-source in general?

If you answered Yes to any of these questions, then
you should seriously consider attending the
RuPy conference in Budapest, Hungary. It’s this
Fall, October 11-13, 2013. The weather in Hungary is great that
time of year, very autumnal but not too cold. I will be posting
more on this in the coming months, as I plan on attending myself.
But for a start, here’s the web site:

Monday, April 15, 2013

CanoScan LiDE 200 on Mountain Lion: Failed to open a Session on the Device because it (the Device) was Locked!

Just a very quick tech note for the Community, since it took me way too long to solve this problem: assuming you have updated your drivers and so on, if your CanoScan LiDE 200 (or similar Canon scanner) still gets you an error in Image Capture on a Mac, the scanner might be locked.

The lock switch is on the bottom of the scanner.

I had by then already updated the drivers, but I probably didn’t need to. Unlock; unplug; re-plug; re-launch Image Capture; voila. It took a while to warm up, but then it had been in storage for two years (which is of course why it was locked).

That did the trick for me. Of course it would have been lovely to have the software say “Your Scanner is Locked, Dumbo!” But I guess it’s a more secure lock if you forget it’s there!