Skip to content
Snippets Groups Projects
Commit 6b0ec830 authored by Michael Hamann's avatar Michael Hamann
Browse files

In debug mode: catch and log JS errors with file information

When debugging is enabled (allowdebug enabled) JS errors are now catched
for each non-core JS file and logged with the additional information
from which file they came. This should make it easier to find out which
plugin is the cause for broken JS code. The feature isn't enabled by
default as defining functions inside try-clauses isn't allowed in strict
mode and causes a warning at least in Firefox.
parent fbd8067e
No related branches found
No related tags found
No related merge requests found
...@@ -104,10 +104,13 @@ function js_out(){ ...@@ -104,10 +104,13 @@ function js_out(){
// load files // load files
foreach($files as $file){ foreach($files as $file){
$ismin = (substr($file,-7) == '.min.js'); $ismin = (substr($file,-7) == '.min.js');
$debugjs = ($conf['allowdebug'] && strpos($file, DOKU_INC.'lib/scripts/') !== 0);
echo "\n\n/* XXXXXXXXXX begin of ".str_replace(DOKU_INC, '', $file) ." XXXXXXXXXX */\n\n"; echo "\n\n/* XXXXXXXXXX begin of ".str_replace(DOKU_INC, '', $file) ." XXXXXXXXXX */\n\n";
if($ismin) echo "\n/* BEGIN NOCOMPRESS */\n"; if($ismin) echo "\n/* BEGIN NOCOMPRESS */\n";
if ($debugjs) echo "\ntry {\n";
js_load($file); js_load($file);
if ($debugjs) echo "\n} catch (e) {\n logError(e, '".str_replace(DOKU_INC, '', $file)."');\n}\n";
if($ismin) echo "\n/* END NOCOMPRESS */\n"; if($ismin) echo "\n/* END NOCOMPRESS */\n";
echo "\n\n/* XXXXXXXXXX end of " . str_replace(DOKU_INC, '', $file) . " XXXXXXXXXX */\n\n"; echo "\n\n/* XXXXXXXXXX end of " . str_replace(DOKU_INC, '', $file) . " XXXXXXXXXX */\n\n";
} }
......
...@@ -68,3 +68,18 @@ function bind(fnc/*, ... */) { ...@@ -68,3 +68,18 @@ function bind(fnc/*, ... */) {
static_args.concat(Aps.call(arguments, 0))); static_args.concat(Aps.call(arguments, 0)));
}; };
} }
/**
* Report an error from a JS file to the console
*
* @param e The error object
* @param file The file in which the error occurred
*/
function logError(e, file) {
if (window.console && console.error) {
console.error('The error "%s: %s" occurred in file "%s". ' +
'If this is in a plugin try updating or disabling the plugin, ' +
'if this is in a template try updating the template or switching to the "default" or "dokuwiki" template.',
e.name, e.message, file);
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment