ysth has asked for the wisdom of the Perl Monks concerning the following question:

I have a module loaded via PerlModule in the .conf file that exists solely to do some consistency checks and die with a verbose error message if they fail so that startup of apache bails out.

This works great, except that instead of just showing the error message (say, "foo\nbar\nbaz\n") on stderr, it looks like:

Syntax error on line 64 of /.../httpd.conf: foo\nbar\nbaz\nCompilation failed in require at (eval 4) line 3.\n
Is there a better way to do this? I don't mind the "Syntax error"/"Compilation failed" being added so much, but I'd really like to get literal newlines in the error message instead of having them translated to \n's.

Replies are listed 'Best First'.
Re: apache2 startup consistency checks
by perrin (Chancellor) on May 18, 2006 at 18:43 UTC
    Try printing to STDERR and then bailing out with CORE::exit(1).
      Thanks for the suggestion.

      I'm going to print to STDERR, then have the module return a false value, assuming that mod_perl will die as gracefully as it requires if that happens. Doing that prints my error message, then a syntax error in httpd.conf message and a Foo.pm dit not return a true value message, which is fine with me.

      That does work, but...

      I see in ModPerl::Util:

      or use C<CORE::exit()>: eval { CORE::exit; } print "Still running"; and nothing will be printed. The problem with the latter is the current process (or a Perl Interpreter) will be killed; something that you really want to avoid under mod_perl.
      (where it's talking about why eval { exit } doesn't actually exit).

      In this case, I do want to actually kill everything, but am still concerned by that "something that you really want to avoid". I was hoping there'd be an actual mod_perl-supplied mechanism to stop the show.

        What that's saying is that you don't want to exit while serving web requests. It's no problem to abort startup by calling exit.
Re: apache2 startup consistency checks
by kwaping (Priest) on May 18, 2006 at 18:21 UTC
    Can you please provide the snippet of code that dies with the error message?

    ---
    It's all fine and dandy until someone has to look at the code.
      Here's a stripped down demonstration:
      $ /opt/apache/bin/httpd -D USER -D DEVELOPMENT $* -f ~/httpd.conf Syntax error on line 64 of /home/yscottthoennes/httpd.conf: One or more of the following files could not be located:\n file1\n + file2\nin the directory /home/yscottthoennes/www_cache. You must ru +n the build script for the missing files prior to Apache startup.\nCo +mpilation failed in require at (eval 4) line 3.\n $ grep Foo httpd.conf PerlModule Foo $ cat Foo.pm package Foo; use strict; use warnings; my $dir = '/home/yscottthoennes/www_cache'; my @reqd_files = qw/ file1 file2 /; die "One or more of the following files could not be located:\n " . join( "\n ", @reqd_files ) . "\nin the directory $dir. " . "You must run the build script for the missing files " . "prior to Apache startup.\n" if ( grep { ! -r "$dir/$_" } @req +d_files ); 1; $