Re: Producing an error page

2000-08-23 Thread Nathan Vonnahme


 -Original Message-
 From: Jay Strauss [mailto:[EMAIL PROTECTED]]

 I've tried the suggestions so far:

 cgi::carp
 http://perl.apache.org/guide/snippets.html#Redirecting_Errors_to_t
 he_Client
 BEGIN { print "Content-Type: text/plain\n\n"; *STDERR = *STDOUT }

Jay,

Below is a module I wrote for doing what you want.  It'll need some name
changing, but the POD at the bottom should explain mostly how to use it.  
One feature is that you can give it a list of "developer" IP addresses
that should see the Perl errors, while other people get a nice bug report
form.  It even works with mod_perl, but beware:  once you use it on one
Registry CGI, all your mod_perl CGIs handle their errors this way.

I don't think I've done everything the most proper or best way but it has
worked in a production environment for a year or so.  I'd welcome comments
or encouragement to put it in CPAN.

Cheers,
nathan
~
Nathan Vonnahme [EMAIL PROTECTED]
http://enteuxis.org/nathan  http://thethirdsector.com


# $Id: CGI_errors.pm,v 1.3 1998/08/26 01:53:55 nathanv Exp $

#  Enteuxis::CGI_errors

# improve CGI error-reporting!  Give an intelligible message to someone on a 
development machine, 
#  or a bug report form to a user and an email report to $alert_email.
#
#  see the pod documentation at the bottom for more...
#
# Copyright 1998 Internet Alaska, Inc.
# 
# written by [EMAIL PROTECTED]


package Enteuxis::CGI_errors;

use vars qw(@ISA @EXPORT $VERSION);
require Exporter;
@ISA = Exporter;
@EXPORT = qw(setup_CGI_errors);

$VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);


use strict;
use CGI::Carp;

my $mailprog = '/usr/lib/sendmail';
my $FORMMAIL_URL = 'http://www.alaska.net/cgi-bin/FormMail.pl';
my $default_email = 'nathan\@enteuxis.org';

my @dev_machines = (
'208.151.124.132',
'inferno.infoinsights.com',
);

my @warnings = ();

sub setup_CGI_errors {
$| = 1;
my $alert_email = shift || $default_email;

$main::SIG{'__WARN__'} = sub {
push @Enteuxis::CGI_errors::warnings, @_ ;
};

$main::SIG{'__DIE__'} = sub {
my $mesg;
# set $header to a valid HTTP header
my $header = "Content-type: text/html\n\n";

if ( ! $ENV{REMOTE_HOST} ||
 (join " ", @dev_machines) =~ /\b$ENV{REMOTE_HOST}\b/ ) {
$mesg = "h1SCRIPT ERROR/h1\n";

$mesg .= "h2WARNINGS:/h2\nul\n";
foreach ( @Enteuxis::CGI_errors::warnings ) { $mesg .= 
"li$_\n"; }
$mesg .= "/ul\nbrhr";
$mesg .= "h2DIE MESSAGE:/h2ulli @_/ulbr";

my($package,$file,$line) = caller();
$mesg .= "bDied/b in $package at $file line $line.\n";

print STDOUT $header . $mesg;
exit;
}
else {
my $url = 
"$ENV{SERVER_URL}$ENV{SCRIPT_NAME}$ENV{PATH_INFO}?$ENV{QUERY_STRING}";
$mesg = qq[
html
headtitleScript Error/title/head
body bgcolor=#ff

h1SCRIPT ERROR/h1

Congratulations!  You've found a bug!  Our staff have been notified and the problem 
should be fixed soon.\n
We'd like it if you can also send us a short description of what you were trying to 
do:hr
form action="$FORMMAIL_URL" method="POST"
input type=hidden name="recipient" value="$alert_email"
input type=hidden name="subject" value="broken CGI comment"
input type=hidden name="the URL in question" value="$url"
Your name (optional)input type=text name="realname" value=""br
Your email address (optional)input type=text name="email" value="\@alaska.net"br
What were you trying to do? textarea name="comment" rows=3 cols=40 
wrap="virtual"/textarea
input type=submit value="mail comments"
/formhr
/body/html
\n\n];
open ERRMAIL, "|$mailprog -t" or die "couldn't open mail pipe- 
$!";
print ERRMAIL "To: $alert_email\n", 
  "From: the.web.server\n", 
  "Subject: $ENV{SCRIPT_NAME} is 
broken!\n\n";

print ERRMAIL "The CGI at $url died!\n\n";
print ERRMAIL "WARNINGS:\n", join( "\n",
@Enteuxis::CGI_errors::warnings ), "\n\n";
print ERRMAIL "DIE MESSAGE:\n@_\n\n";
print ERRMAIL "ENVIRONMENT VARIABLES:\n";
print ERRMAIL "Here are the contents of ENV when this attempt 
to run the script was made:\n";
foreach (keys %ENV) {  
print ERRMAIL sprintf("%-32s", $_), " = $ENV{$_}\n";  }
close ERRMAIL;

RE: Producing an error page

2000-08-23 Thread Perrin Harkins

On Tue, 22 Aug 2000, Howard Jones wrote:

 Something that may be worthwhile as a starting point for you is CGI::Debug

There is an Apache::Debug in the standard distribution.  If you turn on
the debugging flag in Apache::Registry, it looks like it will send the
errors to the client using this module.

- Perrin




RE: Producing an error page

2000-08-22 Thread Howard Jones

Something that may be worthwhile as a starting point for you is CGI::Debug,
which basically does what you are asking I think. It leaves you with the
perl interpreter's error message (as if you had run the thing from a
command-line), a dump of relevant cookies, environment variables and CGI
parameters. I've found it very handy lately for debugging a largeish CGI
app. The only snag is that it doesn't (actually refuses explicitly) work
with mod_perl. Maybe ten minutes work for a mod_perl wizard? ;-)

Regards,

Howard.

 -Original Message-
 From: Jay Strauss [mailto:[EMAIL PROTECTED]]
 Sent: 21 August 2000 16:44
 To: [EMAIL PROTECTED]
 Subject: Re: Producing an error page


 Sorry,

 I didn't explain my question well.  But thanks for all the response.

 I left "my" out of my example on purpose, to illustrate a typical
 (in my case)
 programming error.

 To restate what I'm asking:

 Is there any way to redirect everything that would normally be sent to the
 screen, when I run from the command line, to an HTML page when I
 call my script
 from the browser (on a script by script basis).

 I've tried the suggestions so far:

 cgi::carp
 http://perl.apache.org/guide/snippets.html#Redirecting_Errors_to_t
 he_Client
 BEGIN { print "Content-Type: text/plain\n\n"; *STDERR = *STDOUT }

 None of these methods will print the diagnostic messages, and
 typically only
 print the line number at which I died.

 I'm not in a production environment, so I don't mind getting a
 bunch of ugly
 errors to my browser.

 Thanks again
 Jay

 Jay Strauss
 [EMAIL PROTECTED]
 (h) 773.935.5326
 (c) 312.617.0264

 - Original Message -
 From: "Jay Strauss" [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Monday, August 21, 2000 8:56 AM
 Subject: Producing an error page


 
  Hi,
 
  I'm asking this again, due to lack of response (but I can't
 believe no one out
  there knows how to do this).
 
  How do I produce an error page (in HTML), when I call the script from a
 browser,
  that looks just like the error screen I get when I run a script
 at the command
  line?
 
  That is, if I run the following script from the command line:
 
  ---
  #!/usr/bin/perl -w
 
  use strict;
  use diagnostics;
 
  ($first, $second) = @ARGV;
 
  exit;
  ---
 
  I'll get a whole bunch of messages telling me I "use strict" and I have
  variables that I didn't define with "my".
 
  But, if I call it from my browser, I just get back a "Internal
 Server Error"
  page.  Instead I want all the diagnostics messages.
 
  Thanks
  Jay
 
  Jay Strauss
  [EMAIL PROTECTED]
  (h) 773.935.5326
  (c) 312.617.0264
 
 






Producing an error page

2000-08-21 Thread Jay Strauss

Hi,

I'm asking this again, due to lack of response (but I can't believe no one out
there knows how to do this).

How do I produce an error page (in HTML), when I call the script from a browser,
that looks just like the error screen I get when I run a script at the command
line?

That is, if I run the following script from the command line:

---
#!/usr/bin/perl -w

use strict;
use diagnostics;

($first, $second) = @ARGV;

exit;
---

I'll get a whole bunch of messages telling me I "use strict" and I have
variables that I didn't define with "my".

But, if I call it from my browser, I just get back a "Internal Server Error"
page.  Instead I want all the diagnostics messages.

Thanks
Jay

Jay Strauss
[EMAIL PROTECTED]
(h) 773.935.5326
(c) 312.617.0264





RE: Producing an error page

2000-08-21 Thread Geoffrey Young

http://perl.apache.org/guide/snippets.html#Redirecting_Errors_to_the_Client

HTH

--Geoff

 -Original Message-
 From: Jay Strauss [mailto:[EMAIL PROTECTED]]
 Sent: Monday, August 21, 2000 9:56 AM
 To: [EMAIL PROTECTED]
 Subject: Producing an error page
 
 
 Hi,
 
 I'm asking this again, due to lack of response (but I can't 
 believe no one out
 there knows how to do this).
 
 How do I produce an error page (in HTML), when I call the 
 script from a browser,
 that looks just like the error screen I get when I run a 
 script at the command
 line?
 
 That is, if I run the following script from the command line:
 
 ---
 #!/usr/bin/perl -w
 
 use strict;
 use diagnostics;
 
 ($first, $second) = @ARGV;
 
 exit;
 ---
 
 I'll get a whole bunch of messages telling me I "use strict" 
 and I have
 variables that I didn't define with "my".
 
 But, if I call it from my browser, I just get back a 
 "Internal Server Error"
 page.  Instead I want all the diagnostics messages.
 
 Thanks
 Jay
 
 Jay Strauss
 [EMAIL PROTECTED]
 (h) 773.935.5326
 (c) 312.617.0264
 
 



Re: Producing an error page

2000-08-21 Thread Tim Sweetman

Have a look at CGI::Carp.

Jay Strauss wrote:
 
 Hi,
 
 I'm asking this again, due to lack of response (but I can't believe no one out
 there knows how to do this).
 
 How do I produce an error page (in HTML), when I call the script from a browser,
 that looks just like the error screen I get when I run a script at the command
 line?

Cheers

--
Tim Sweetman



Re: Producing an error page

2000-08-21 Thread Flemming Mahler Larsen

On Mon, 21 Aug 2000, Jay Strauss wrote:

 ---
 #!/usr/bin/perl -w
 
 use strict;
 use diagnostics;

Try adding:
use CGI::Carp; # send error messages to browser

 
 ($first, $second) = @ARGV;
Try:
my ($first, $second) = @ARGV;

You may also want to check "my" in a Perl book, just so you know what it
does :-)

// Flemming
--
Flemming Mahler Larsen, Tele Danmark Internet
http://projekt.tele.dk.net/about/mahler.html // +45 3527 9013





RE: Producing an error page

2000-08-21 Thread Shimon Rura

Jay, although others have recommended you look at the mod_perl guide and
CGI::Carp, I don't think these are exactly what you're looking for.  The
errors you are getting are generated because of 'use strict;' and occur at
compile time; CGI::Carp is capable of redirecting errors to the browser (if
you type "use CGI::Carp 'fatalsToBrowser'").  Hence your script doesn't get
to run at all, and it doesn't produce anything on standard output.  Your web
server redirects this STDOUT to the web browser and redirects STDERR to its
error log.  Also, you never print a valid content-type header on STDOUT so
your web server can't grok it anyway.  What you need to do is send your
ERRORS to STDOUT instead of STDERR and precede their output with
"Content-Type: text/plain\n\n".  I am not totally sure this is possible
(it's a very odd thing to do) but you might try inserting this at the top of
your script (BEFORE 'use strict;'):

BEGIN { print "Content-Type: text/plain\n\n"; *STDERR = *STDOUT }

This is a BEGIN block which is evaluated at compile time.

I'll give this a try, and you can too.  But I wouldn't be surprised if this
just resulted in weirder behavior.  Chances are what you want to do isn't
really the best thing for your situation, perhaps you could describe your
reason for wanting this behavior.  Good luck!

shimon.

p.s. This wasn't really a mod_perl related question, perhaps this wasn't the
best forum to ask it.

Jay Strauss said:

 Hi,

 I'm asking this again, due to lack of response (but I can't
 believe no one out
 there knows how to do this).

 How do I produce an error page (in HTML), when I call the script
 from a browser,
 that looks just like the error screen I get when I run a script
 at the command
 line?

 That is, if I run the following script from the command line:

 ---
 #!/usr/bin/perl -w

 use strict;
 use diagnostics;

 ($first, $second) = @ARGV;

 exit;
 ---

 I'll get a whole bunch of messages telling me I "use strict" and I have
 variables that I didn't define with "my".

 But, if I call it from my browser, I just get back a "Internal
 Server Error"
 page.  Instead I want all the diagnostics messages.

 Thanks
 Jay

 Jay Strauss
 [EMAIL PROTECTED]
 (h) 773.935.5326
 (c) 312.617.0264




Re: Producing an error page

2000-08-21 Thread Jay Strauss

Sorry,

I didn't explain my question well.  But thanks for all the response.

I left "my" out of my example on purpose, to illustrate a typical (in my case)
programming error.

To restate what I'm asking:

Is there any way to redirect everything that would normally be sent to the
screen, when I run from the command line, to an HTML page when I call my script
from the browser (on a script by script basis).

I've tried the suggestions so far:

cgi::carp
http://perl.apache.org/guide/snippets.html#Redirecting_Errors_to_the_Client
BEGIN { print "Content-Type: text/plain\n\n"; *STDERR = *STDOUT }

None of these methods will print the diagnostic messages, and typically only
print the line number at which I died.

I'm not in a production environment, so I don't mind getting a bunch of ugly
errors to my browser.

Thanks again
Jay

Jay Strauss
[EMAIL PROTECTED]
(h) 773.935.5326
(c) 312.617.0264

- Original Message -
From: "Jay Strauss" [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, August 21, 2000 8:56 AM
Subject: Producing an error page



 Hi,

 I'm asking this again, due to lack of response (but I can't believe no one out
 there knows how to do this).

 How do I produce an error page (in HTML), when I call the script from a
browser,
 that looks just like the error screen I get when I run a script at the command
 line?

 That is, if I run the following script from the command line:

 ---
 #!/usr/bin/perl -w

 use strict;
 use diagnostics;

 ($first, $second) = @ARGV;

 exit;
 ---

 I'll get a whole bunch of messages telling me I "use strict" and I have
 variables that I didn't define with "my".

 But, if I call it from my browser, I just get back a "Internal Server Error"
 page.  Instead I want all the diagnostics messages.

 Thanks
 Jay

 Jay Strauss
 [EMAIL PROTECTED]
 (h) 773.935.5326
 (c) 312.617.0264






Re: Producing an error page

2000-08-21 Thread Rob Tanner

The stuff that the server sends back comes from STDOUT if CGIs or within 
mod-perl, either $req-print or a regular print since it is tied.  The 
error messages go to STDERR which apache redirects internalls so that the 
messages go to the error log.  I don't know that it's possible and I'm 
certain it's not a good idea to try and circumvent that and send STDERR to 
the browser.  And besides that, you'd still have to send content-type 
headers.  I suppose you could write one perl program that executes your 
perl program of interest from within an eval block and capture the output 
that way.  But isn't simply looking at the error log easier?

-- Rob

--On Monday, August 21, 2000 8:56 AM -0500 Jay Strauss 
[EMAIL PROTECTED] wrote:

 Hi,

 I'm asking this again, due to lack of response (but I can't believe no
 one out there knows how to do this).

 How do I produce an error page (in HTML), when I call the script from a
 browser, that looks just like the error screen I get when I run a script
 at the command line?

 That is, if I run the following script from the command line:

 ---
 #!/usr/bin/perl -w

 use strict;
 use diagnostics;

 ($first, $second) = @ARGV;

 exit;
 ---

 I'll get a whole bunch of messages telling me I "use strict" and I have
 variables that I didn't define with "my".

 But, if I call it from my browser, I just get back a "Internal Server
 Error" page.  Instead I want all the diagnostics messages.

 Thanks
 Jay

 Jay Strauss
 [EMAIL PROTECTED]
 (h) 773.935.5326
 (c) 312.617.0264






   _ _ _ _   __ _ _ _ _
  /\_\_\_\_\/\_\ /\_\_\_\_\_\
 /\/_/_/_/_/   /\/_/ \/_/_/_/_/_/  QUIDQUID LATINE DICTUM SIT,
/\/_/__\/_/ __/\/_//\/_/  PROFUNDUM VIDITUR
   /\/_/_/_/_/ /\_\  /\/_//\/_/
  /\/_/ \/_/  /\/_/_/\/_//\/_/ (Whatever is said in Latin
  \/_/  \/_/  \/_/_/_/_/ \/_/  appears profound)

  Rob Tanner
  McMinnville, Oregon
  [EMAIL PROTECTED]



Re: Producing an error page

2000-08-21 Thread George Sanderson

At first, when I read the first message, I said to myself; (self) Why would
anyone want an error page with all the Perl HTML STDOUT/STDOUT stuff mixed
up together?  However, after reading and thinking some more, . . . (just
from a conceptional point of view and not from an implementation view
point), , , what a powerful concept!  If you (a developer) could regain the
Perl command line style of output from the web server (itself) without
having to piece together the STDOUT/STDERR during a debugging effort.  Now,
lets say that you had an Apache module that output a web page that looked
just like the stuff you could see from  the browsers "View/(Page)Source"
with the STDERR output included.  All one would have to do, is configure
the DEBUG handler in the httpd.conf, which would in turn produce what
appeared as HTML code with STDOUT included all within a HTML page.  The
STDERR output would be distinguished, with lets say:
 STDERR Opps got an error here or something. \STDERR
I'm sure you would also want a submit (DEBUG) button which could generate
the above, on-demand for form pages and such. (Kind of a DEBUG on demand
option.)

Is this what is being discussed here?  
(This is probably, not a mod_perl topic, but then again, it could be:-).


At 12:04 PM 8/21/00 -0700, you wrote:
The stuff that the server sends back comes from STDOUT if CGIs or within 
mod-perl, either $req-print or a regular print since it is tied.  The 
error messages go to STDERR which apache redirects internalls so that the 
messages go to the error log.  I don't know that it's possible and I'm 
certain it's not a good idea to try and circumvent that and send STDERR to 
the browser.  And besides that, you'd still have to send content-type 
headers.  I suppose you could write one perl program that executes your 
perl program of interest from within an eval block and capture the output 
that way.  But isn't simply looking at the error log easier?

-- Rob

--On Monday, August 21, 2000 8:56 AM -0500 Jay Strauss 
[EMAIL PROTECTED] wrote:

 Hi,

 I'm asking this again, due to lack of response (but I can't believe no
 one out there knows how to do this).

 How do I produce an error page (in HTML), when I call the script from a
 browser, that looks just like the error screen I get when I run a script
 at the command line?

 That is, if I run the following script from the command line:

 ---
 #!/usr/bin/perl -w

 use strict;
 use diagnostics;

 ($first, $second) = @ARGV;

 exit;
 ---

 I'll get a whole bunch of messages telling me I "use strict" and I have
 variables that I didn't define with "my".

 But, if I call it from my browser, I just get back a "Internal Server
 Error" page.  Instead I want all the diagnostics messages.

 Thanks
 Jay

 Jay Strauss
 [EMAIL PROTECTED]
 (h) 773.935.5326
 (c) 312.617.0264





Re: Producing an error page

2000-08-21 Thread ___cliff rayman___

i may be coming in late here, so forgive me if this has been mentioned:

use CGI::Carp qw(fatalsToBrowser);

not sure if everything you want will be sent to the browser, but it is better
than a standard 500 error, and you can read the errors from the log easier.
--
___cliff [EMAIL PROTECTED]http://www.genwax.com/
George Sanderson wrote:


  STDERR Opps got an error here or something. \STDERR
 I'm sure you would also want a submit (DEBUG) button which could generate
 the above, on-demand for form pages and such. (Kind of a DEBUG on demand
 option.)

 Is this what is being discussed here?
 (This is probably, not a mod_perl topic, but then again, it could be:-).

 At 12:04 PM 8/21/00 -0700, you wrote:
 The stuff that the server sends back comes from STDOUT if CGIs or within
 mod-perl, either $req-print or a regular print since it is tied.  The
 error messages go to STDERR which apache redirects internalls so that the
 messages go to the error log.  I don't know that it's possible and I'm
 certain it's not a good idea to try and circumvent that and send STDERR to
 the browser.  And besides that, you'd still have to send content-type
 headers. ==

--snip--


  How do I produce an error page (in HTML), when I call the script from a
  browser, that looks just like the error screen I get when I run a script
  at the command line?
 
  That is, if I run the following script from the command line:
 
  ---
  #!/usr/bin/perl -w
 
  use strict;
  use diagnostics;
 
  ($first, $second) = @ARGV;
 
  exit;
  ---
 
  I'll get a whole bunch of messages telling me I "use strict" and I have
  variables that I didn't define with "my".
 
  But, if I call it from my browser, I just get back a "Internal Server
  Error" page.  Instead I want all the diagnostics messages.
 
  Thanks
  Jay
 
  Jay Strauss
  [EMAIL PROTECTED]
  (h) 773.935.5326
  (c) 312.617.0264