better exception handling on plugin loading
Now all important places where plugins are loaded are guarded by a try/except. We're catching Throwables here to be able to catch stuff like syntax errors early on (otherwise they will only be caught by our ErrorConverter much too late). This means that this change requires PHP 7.0 minimum!
This commit is contained in:
parent
0e69c9aff9
commit
ffa84f8121
|
@ -57,9 +57,9 @@ EOT;
|
|||
*/
|
||||
public static function showExceptionMsg($e, $intro = 'Error!')
|
||||
{
|
||||
$msg = $intro . get_class($e) . ': ' . $e->getMessage();
|
||||
self::logException($e);
|
||||
msg(hsc($msg), -1);
|
||||
$msg = hsc($intro).'<br />' . hsc(get_class($e) . ': ' . $e->getMessage());
|
||||
if(self::logException($e)) $msg .= '<br />More info is available in the _error.log';
|
||||
msg($msg, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -129,7 +129,7 @@ class PluginController
|
|||
}
|
||||
$DOKU_PLUGINS[$type][$name] = new $class;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Throwable $e) {
|
||||
ErrorHandler::showExceptionMsg($e, sprintf('Failed to load plugin %s', $plugin));
|
||||
return null;
|
||||
}
|
||||
|
|
18
inc/load.php
18
inc/load.php
|
@ -108,7 +108,11 @@ function load_autoload($name){
|
|||
$name = str_replace('/test/', '/_test/', $name); // no underscore in test namespace
|
||||
$file = DOKU_PLUGIN . substr($name, 16) . '.php';
|
||||
if(file_exists($file)) {
|
||||
require $file;
|
||||
try {
|
||||
require $file;
|
||||
} catch (\Throwable $e) {
|
||||
\dokuwiki\ErrorHandler::showExceptionMsg($e, "Error loading plugin $name");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +122,11 @@ function load_autoload($name){
|
|||
$name = str_replace('/test/', '/_test/', $name); // no underscore in test namespace
|
||||
$file = DOKU_INC.'lib/tpl/' . substr($name, 18) . '.php';
|
||||
if(file_exists($file)) {
|
||||
require $file;
|
||||
try {
|
||||
require $file;
|
||||
} catch (\Throwable $e) {
|
||||
\dokuwiki\ErrorHandler::showExceptionMsg($e, "Error loading template $name");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -144,7 +152,11 @@ function load_autoload($name){
|
|||
$c = ((count($m) === 4) ? "/{$m[3]}" : '');
|
||||
$plg = DOKU_PLUGIN . "{$m[2]}/{$m[1]}$c.php";
|
||||
if(file_exists($plg)){
|
||||
require $plg;
|
||||
try {
|
||||
require $plg;
|
||||
} catch (\Throwable $e) {
|
||||
\dokuwiki\ErrorHandler::showExceptionMsg($e, "Error loading plugin ${$m[2]}");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue