diff options
author | Arne Georg Gleditsch <argggh@lxr.linpro.no> | 2008-02-17 23:05:18 +0100 |
---|---|---|
committer | Arne Georg Gleditsch <argggh@lxr.linpro.no> | 2008-02-17 23:05:18 +0100 |
commit | 32aa8b091f439043ec2a4c7807366cb26eb9de19 (patch) | |
tree | ee64267c7a43aaf412edbf0a9bfcb9f95b871885 | |
parent | dd670fda9351186a1bf51de2a3b8192a9cda301c (diff) |
Improved error handling.
-rw-r--r-- | lib/LXRng/Context.pm | 2 | ||||
-rw-r--r-- | lib/LXRng/Web.pm | 50 | ||||
-rw-r--r-- | tmpl/bare_error.tt2 | 20 | ||||
-rw-r--r-- | tmpl/error.tt2 | 3 | ||||
-rw-r--r-- | tmpl/header.tt2 | 24 | ||||
-rw-r--r-- | tmpl/search_result.tt2 | 4 |
6 files changed, 85 insertions, 18 deletions
diff --git a/lib/LXRng/Context.pm b/lib/LXRng/Context.pm index 6909c58..db486bf 100644 --- a/lib/LXRng/Context.pm +++ b/lib/LXRng/Context.pm @@ -82,7 +82,7 @@ sub new { if ($$self{'tree'} and $$self{'tree'} !~ /^[+]/) { my $tree = $$self{'tree'}; - die("No config for tree $tree") + return $self unless exists($$config{$tree}); $$self{'config'} = $$config{$tree}; diff --git a/lib/LXRng/Web.pm b/lib/LXRng/Web.pm index 78380c8..e616170 100644 --- a/lib/LXRng/Web.pm +++ b/lib/LXRng/Web.pm @@ -170,6 +170,28 @@ sub print_markedup_file { } } +sub print_error { + my ($context, $template, $query, $error) = @_; + + my $tmpl; + if ($context->config and $context->config->{'repository'}) { + $tmpl = 'error.tt2'; + } + else { + $tmpl = 'bare_error.tt2'; + } + + print($query->header(-type => 'text/html', + -charset => 'utf-8')); + + my $base = $context->base_url(); + $template->process($tmpl, + {'context' => $context, + 'base_url' => $base, + 'error' => $error}) + or die $template->error(); +} + sub print_tree_list { my ($context, $template) = @_; @@ -243,10 +265,18 @@ sub source { my $ver = $context->release; my $rep = $context->config->{'repository'}; - die "No tree given" unless $rep; + unless ($rep) { + print_error($context, $template, $query, + "No/unknown tree indicated"); + return; + } my $node = $rep->node($context->path, $ver); - die "Node not found: ".$context->path." ($ver)" unless $node; + unless ($node) { + print_error($context, $template, $query, + "Node not found: ".$context->path." ($ver)"); + return; + } my $gzip = do_compress_response($query); @@ -404,13 +434,13 @@ sub search { my $rep = $context->config->{'repository'}; my @args = grep { $rep->node($_, $context->release) - } split(/\|/, $find); + } split(/\|/, $find); $template_args{'ambig_res'} = {'query' => $find, 'files' => \@args,} } } else { - die "No query string given"; + $template_args{'error'} = 'No query string given'; } my $html = ''; $template_args{'tree'} = $context->tree; @@ -473,6 +503,10 @@ sub handle_ajax_request { binmode(\*STDOUT, ":gzip") if $gzip; if ($context->param('fname') eq 'pjx_load_file') { + unless ($context->config and $context->config->{'repository'}) { + print('<div class="error">No/unknown tree indicated.</div>'); + return; + } my $rep = $context->config->{'repository'}; my $node = $rep->node($context->param('file'), $context->release); print_markedup_file($context, $template, $node); @@ -773,8 +807,14 @@ sub generate_pdf { sub handle { my ($self, $query) = @_; - my $context = LXRng::Context->new('query' => $query); my $template = Template->new({'INCLUDE_PATH' => $LXRng::ROOT.'/tmpl/'}); + my $context = LXRng::Context->new('query' => $query); + + unless ($context->config) { + print_error($context, $template, $query, + "No/unknown tree indicated"); + return; + } if ($context->param('fname')) { handle_ajax_request($query, $context, $template); diff --git a/tmpl/bare_error.tt2 b/tmpl/bare_error.tt2 new file mode 100644 index 0000000..03f6aeb --- /dev/null +++ b/tmpl/bare_error.tt2 @@ -0,0 +1,20 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" +"http://www.w3.org/TR/html4/loose.dtd"> +<html lang="en"> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> + <title id="title">LXR Error</title> + + <style type="text/css"> + div.error { + font-weight: bold; + font-style: italic; + color: #E04040; + } + </style> + + </head> + <body> + <div class="error">[% error | html %]</div> + </body> +</html> diff --git a/tmpl/error.tt2 b/tmpl/error.tt2 new file mode 100644 index 0000000..b8996ac --- /dev/null +++ b/tmpl/error.tt2 @@ -0,0 +1,3 @@ +[% INCLUDE header.tt2 %] +<div class="error">[% error | html %]</div> +[% INCLUDE footer.tt2 %] diff --git a/tmpl/header.tt2 b/tmpl/header.tt2 index 2932823..106f3bd 100644 --- a/tmpl/header.tt2 +++ b/tmpl/header.tt2 @@ -10,19 +10,19 @@ var startup_tree = location.hash.match(/^#([^/+]+)([+][^/]*|)/); if (startup_tree) { - var base = '[% base_url %]'; + var base = '[% base_url | html %]'; base = base.replace(/\/ajax[+][*]/, '/' + startup_tree[1] + '+*'); document.write('<base href="' + base + '">'); } else { - document.write('<base href="[% base_url %]">'); + document.write('<base href="[% base_url | html %]">'); document.write('<meta http-equiv="Refresh" content="1;+trees">'); use_ajax_navigation = 0; } [% END %] </script> [% IF !is_ajax %] - <base href="[% base_url %]"> + <base href="[% base_url | html %]"> [% END %] <script type="text/javascript" src="../.static/js/lxrng-funcs.js"></script> <link rel="stylesheet" href="../.static/css/lxrng.css" type="text/css" title="LXRng"> @@ -32,8 +32,8 @@ <script type="text/javascript"> </script> - <title>LXR [% context.tree -%]/ - [%- FOREACH elem = context.path_elements %][% elem.node %][% END %] + <title>LXR [% context.tree | html -%]/ + [%- FOREACH elem = context.path_elements %][% elem.node | html %][% END %] </title> </head> @@ -47,15 +47,15 @@ <span class="lxr_title"> <span class="lxr_logo"><a href="..">LXR</a></span> <span id="current_path"> - <a href="../[% context.vtree %]/">[% context.tree %]/</a>[% + <a href="../[% context.vtree | html %]/">[% context.tree | html%]/</a>[% FOREACH elem = context.path_elements - %]<a href="[% elem.path %]">[% elem.node %]</a>[% + %]<a href="[% elem.path | html %]">[% elem.node | html %]</a>[% END %] </span> <img src="../.static/gfx/rolldown.png" alt="History"> <span id="lxr_print" [% IF is_ajax || node.name.match('/$') %]style="display: none;"[% END %]> - <form action="+print=[% node.name %]" method="post" id="print_form"> + <form action="+print=[% node.name | html %]" method="post" id="print_form"> <button type="submit" class="print"> <img src="../.static/gfx/print.png" alt="Print"> </button> @@ -66,15 +66,15 @@ <div class="lxr_menu"> <span class="lxr_version"> <a [% IF is_ajax %]href="#" onclick="return previous_version();"[% ELSE %] - href="../[% context.tree %]+[% ver_prev %]/[% node.name %]"[% END %]> + href="../[% context.tree | html %]+[% ver_prev | html %]/[% node.name | html %]"[% END %]> <img src="../.static/gfx/left.png" alt="<<"></a> - <form action="[% node.name %]" method="get"> + <form action="[% node.name | html %]" method="get"> <span id="ver_select"> [% INCLUDE release_select.tt2, context = context %] </span> </form> <a [% IF is_ajax %]href="#" onclick="return next_version();"[% ELSE %] - href="../[% context.tree %]+[% ver_next %]/[% node.name %]"[% END %]> + href="../[% context.tree | html %]+[% ver_next | html %]/[% node.name | html %]"[% END %]> <img src="../.static/gfx/right.png" alt=">>"></a> </span> @@ -87,7 +87,7 @@ </span> <span class="lxr_prefs"> - <a href="+prefs?return=[% node.name %]" + <a href="+prefs?return=[% node.name | html %]" onclick="return ajax_prefs();"> Prefs </a> diff --git a/tmpl/search_result.tt2 b/tmpl/search_result.tt2 index 7ba14f9..afc36f4 100644 --- a/tmpl/search_result.tt2 +++ b/tmpl/search_result.tt2 @@ -3,6 +3,10 @@ <img border="0" src="../.static/gfx/close.png" alt="X"></a> </span> +[% IF error %] +<div class="error">[% error | html %]</div> +[% END %] + [% IF search_type == "code" or (code_res and code_res.idents.0) %] <div class="query_desc">Code search: [% code_res.query %]</div> [% ptype = '' %] |