#168 Display something if initialization failed

current_cvs
closed-accepted
Andre-Littoz
Browsing (93)
5
2011-03-12
2011-03-09
Andre-Littoz
No

LXR v0.8.9

In case something goes wrong with initialization (config read in), LXR silently dies (from the user point of view). Error message is sent to server
error log which cannot be read by ordinary user. In the best case, displayed page does not change hinting at a no-op for the click. In the worst case, you get a blank screen which is really puzzling.

If it is not too bad, try to send an error page (only case presently managed: no baseurl found). For that, modify Config.pm so that a new property of object $config signals the cause of error. This property has been chosen to be 'configerror'. It is created when Config.pm::initialize detects an error. Caller may then test for this existence of this property and act accordingly.

Since this error signalling was needed by my use of URL to tell which tree to display in a multi-tree DB, there is also an addition to manipulate the URL to provide a meaningful informative message. In my usage, the tree name is located right before the script (i.e. source, ident, ...). It is printed in the message to show the eventual typo.

In lxr.conf, you may add a global parameter like:
'treeextract' => '([^/]*)/[^/]*$'
which is pattern against the SCRIPT_NAME part of the URL. $1 is used in the error message. If you need grouping before your target, use (?: instead of (.

Proposed patch:
1- Common.pm
in sub httpinit:

!-496,496 110226 (replace line 496 with:)
! if (exists $config->{'configerror'}) {
! makeerrorpage('htmlfatal');
! die "Can't find config for " . $HTTP->{'this_url'};
! };
----------------------- end of patch -------------------------------

Create anew sub makeerrorpage to issue an error page instead of 'Die'ing silently.
Since LXR is badly initialized, use as few features as possible.
For instance, if you don't trust a smart lxr.conf, don't use 'stylesheet' in your error page template. Anyway, if 'stylesheet' does not exist, the page is still built without substitution; it might do funny things to the UA but anyhow the page is displayed with default styles.
Added a 'treeextract' parameter to provide a pattern (regexp) to extract the source tree name from URL since where to put it is a matter of personal taste.
If 'treeextract' does not exist, extract the second to last part of SCRIPT_NAME.

!-895 110226 & 110301 (after line 895, insert:)
!sub makeerrorpage {
! my $who = shift;
! my $tmplname;
! my $template = "<html><body><hr>\n"
! . "<div align='center'>\n"
! . "<h1>Unrecoverable Error</h1><br>\n"
! . "\$tree unknown\n"
! . "</div>\n</body></html>\n";
!
! $tmplname = $who;
!
! if ($config->value($tmplname)) {
! if (open(TEMPL, $config->value($tmplname))) {
! local ($/) = undef;
! $template = <TEMPL>;
! close(TEMPL);
! } else {
! warning("Template " . $config->value($tmplname) . " does not exist in ".`pwd`);
! }
! }
!
! print("Content-Type: text/html; charset=iso-8859-1\n");
! print("\n");
!
! my $treeextract = '([^/]*)/[^/]*$'; # default: capture second to last fragment
! if (exists ($config->{'treeextract'})) {
! $treeextract = $config->treeextract;
! }
!
! print(
! expandtemplate(
! $template,
! (
! 'tree' => sub { $_ = $ENV{'SCRIPT_NAME' }; m!$treeextract!; return $1; },
! 'stylesheet' => sub { stylesheet(@_) },
! )
! )
! );
! $config = undef;
! $files = undef;
! $index = undef;
!}
!
----------------- end of patch ----------------

2- Config.pm

in sub initialize
In case something goes wrong with initialization (config read in), LXR silently dies (from the user point of view).
Create 'configerror' to tell caller something went screwy. Value explains why.
Don't do it for genxref, since it is executed from the console and STDERR is
displayed normally. There, it is better to stop the script.
!-111,112 110226 (replace lines 111 and 112 with:)
! if(!exists $self->{baseurl}) {
! if("genxref" ne ($0 =~ /([^\/]*)$/)) {
! $$self{'configerror'} = "nobaseurl"; return 1;
! } elsif($url =~ m!http://.+\.!) {
----------------- end of patch -----------------

Discussion

  • Andre-Littoz
    Andre-Littoz
    2011-03-09

    • status: open --> open-works-for-me
     
  • Andre-Littoz
    Andre-Littoz
    2011-03-11

    • assigned_to: nobody --> ajlittoz
     
  • Andre-Littoz
    Andre-Littoz
    2011-03-12

    This has now been fixed in CVS.

    If you can install the new version and check that it solves your
    problem, then it would be very useful.

    Thanks for reporting this defect and helping to make LXR better.

     
  • Andre-Littoz
    Andre-Littoz
    2011-03-12

    • status: open-works-for-me --> closed-accepted
     
  • Andre-Littoz
    Andre-Littoz
    2011-03-12

    Incorporated in CVS