Network.CGI and error handling

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Network.CGI and error handling

Ketil Malde-5

Hi,

I'm trying to implement a CGI, but I have encountered some problems
with handling program errors properly. I think it boils down to this:

The first program from the documentation at
http://hackage.haskell.org/packages/archive/cgi/3001.1.5.2/doc/html/Network-CGI.html

   import Network.CGI
   cgiMain = output "Hello World!"
   main = runCGI (handleErrors cgiMain)

works fine, and ouputs a page with the expected test.  Replacing line
2 with:

   cgiMain = output $ error "Hello World!"

returns a blank page, although according to the documentation,
'handleErrors' should produce an error page (500) instead.

The error is recorded in the log, where one can read:

   [Thu May 22 14:35:27 2008] [error] [client 10.1.9.227] test.cgi: Hello World!

I've toyed with various approaches, including using catchCGI and
replacing 'error' with other run-time failures, but only getting the
same result.  Any hints?

(ghc 6.8.1, cgi-3001.1.5.1, apache 2.0, linux.)

-k
--
If I haven't seen further, it is by standing in the footprints of giants
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Network.CGI and error handling

Ketil Malde-5

Since Björn Bringert suggested (on IRC) the problem could be due to
laziness, and that I should force the result string before giving it
to "output", I've been playing around a bit.  (The program is somewhat
more involved than the short test I provided earlier, but available on
request).

Without strictness, I get a blank page, and an message in the
error_log:

  [Thu May 22 22:00:15 2008] [error] [client 10.1.4.222] snp.cgi: Prelude.last: empty list, referer: http://gadidae/snp.c
gi

This is okay, but I would still like some output to the user.  With
strict evaluation of output's argument, I instead get a web page that
appears to hang (showing a hourglass cursor and animated toolbar
icon).  In the log, I find:

  [Thu May 22 22:22:44 2008] [error] [client 10.1.4.222] Premature end of script headers: snp-strict.cgi, referer: http://gadidae/snp-strict.cgi
  [Thu May 22 22:26:32 2008] [error] [client 10.1.4.222] Premature end of script headers: snp-strict.cgi, referer: http://gadidae/snp-strict.cgi
  [Thu May 22 22:27:44 2008] [error] [client 10.1.4.222] (500,"Internal Server Error",["Prelude.last: empty list"]), referer: http://gadidae/snp-strict.cgi
  [Thu May 22 22:31:32 2008] [error] [client 10.1.4.222] (500,"Internal Server Error",["Prelude.last: empty list"]), referer: http://gadidae/snp-strict.cgi

I interpret this as the system putting things on hold for about ten minutes
before terminating my script, and for some reason, the intended error
document is put in the log instead of being returned to the
browser/client. This is just weird.

(I do actually get a 500 from the server, but that just talks about
"premature end of script headers", and not about the actual bug in my
program, so I belive this is just what apache says when terminating a
runaway cgi)

Network.CGI does look like an established library, certainly the
documentation I find is very good and complete, and the interface is
concise, logical, and to the point.  It seems a shame that it doesn't
work.  Does anybody else have it working?  I'd be very happy to hear
about it, even if it just works for you.

-k
--
If I haven't seen further, it is by standing in the footprints of giants
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Network.CGI and error handling

Ketil Malde-5
Ketil Malde <[hidden email]> writes:

> Since Björn Bringert suggested (on IRC) the problem could be due to
> laziness [..] Does anybody else have it working?

I found that other person, and he is us.  I played around some more,
and thought -- just to not leave any stone unturned -- that I should
try it on a different web server.  So, I moved my CGIs over, and lo
and behold, the strict version suddenly works!

I therefore would like to apologize for any insinuation I may have
perpetrated that could be taken to imply that Network.CGI possesses
any feature of less than desirable merit¹.  As usual, it's some C
program that is to blame :-)

-k

¹ I'm tempted to suggest that "output" should be strict in its
argument, but I shall refrain.
--
If I haven't seen further, it is by standing in the footprints of giants
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe