Error handling improvement for preprocess hooks. It's now safe to call error() from such hooks; it will cause a nicely formatted error message to be inserted into the page.
parent
2bd4dea7f0
commit
edb59cd5b9
27
IkiWiki.pm
27
IkiWiki.pm
|
@ -768,21 +768,30 @@ sub preprocess ($$$;$$) { #{{{
|
||||||
}
|
}
|
||||||
my $ret;
|
my $ret;
|
||||||
if (! $scan) {
|
if (! $scan) {
|
||||||
$ret=$hooks{preprocess}{$command}{call}->(
|
$ret=eval {
|
||||||
@params,
|
|
||||||
page => $page,
|
|
||||||
destpage => $destpage,
|
|
||||||
preview => $preprocess_preview,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
# use void context during scan pass
|
|
||||||
$hooks{preprocess}{$command}{call}->(
|
$hooks{preprocess}{$command}{call}->(
|
||||||
@params,
|
@params,
|
||||||
page => $page,
|
page => $page,
|
||||||
destpage => $destpage,
|
destpage => $destpage,
|
||||||
preview => $preprocess_preview,
|
preview => $preprocess_preview,
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
if ($@) {
|
||||||
|
chomp $@;
|
||||||
|
$ret="[[!$command <span class=\"error\">".
|
||||||
|
gettext("Error").": $@"."</span>]]";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
# use void context during scan pass
|
||||||
|
eval {
|
||||||
|
$hooks{preprocess}{$command}{call}->(
|
||||||
|
@params,
|
||||||
|
page => $page,
|
||||||
|
destpage => $destpage,
|
||||||
|
preview => $preprocess_preview,
|
||||||
|
);
|
||||||
|
};
|
||||||
$ret="";
|
$ret="";
|
||||||
}
|
}
|
||||||
$preprocessing{$page}--;
|
$preprocessing{$page}--;
|
||||||
|
|
|
@ -20,6 +20,9 @@ ikiwiki (2.54) UNRELEASED; urgency=low
|
||||||
* Move yesno function out of inline and into IkiWiki core, not exported.
|
* Move yesno function out of inline and into IkiWiki core, not exported.
|
||||||
* meta: fix title() PageSpec (smcv)
|
* meta: fix title() PageSpec (smcv)
|
||||||
* Some footer style changes. (smcv)
|
* Some footer style changes. (smcv)
|
||||||
|
* Error handling improvement for preprocess hooks. It's now safe to call
|
||||||
|
error() from such hooks; it will cause a nicely formatted error message
|
||||||
|
to be inserted into the page.
|
||||||
|
|
||||||
-- Josh Triplett <josh@freedesktop.org> Wed, 09 Jul 2008 21:30:33 -0700
|
-- Josh Triplett <josh@freedesktop.org> Wed, 09 Jul 2008 21:30:33 -0700
|
||||||
|
|
||||||
|
|
|
@ -412,12 +412,13 @@ Aborts with an error message. If the second parameter is passed, it is a
|
||||||
function that is called after the error message is printed, to do any final
|
function that is called after the error message is printed, to do any final
|
||||||
cleanup.
|
cleanup.
|
||||||
|
|
||||||
Note that while any plugin can use this for a fatal error, plugins should
|
If called inside a preprocess hook, error() does not abort the entire
|
||||||
try to avoid dying on bad input when building a page, as that will halt
|
wiki build, but instead replaces the [[ikiwiki/PreProcessorDirective]] with
|
||||||
the entire wiki build and make the wiki unusable. So for example, if a
|
a version containing the error message.
|
||||||
[[ikiwiki/PreProcessorDirective]] is passed bad parameters, it's better to
|
|
||||||
return an error message, which can appear on the wiki page, rather than
|
In other hooks, error() is a fatal error, so use with care. Try to avoid
|
||||||
calling error().
|
dying on bad input when building a page, as that will halt
|
||||||
|
the entire wiki build and make the wiki unusable.
|
||||||
|
|
||||||
#### `template($;@)`
|
#### `template($;@)`
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue