From 21c58e9fab85f6391f93311ad6ce2afe984840e3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 29 May 2020 15:29:47 +0200 Subject: [PATCH] Error management --- htdocs/modulebuilder/index.php | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index f3e9ec9c190..3e5b99ca5b8 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -485,6 +485,7 @@ if ($dirins && $action == 'initcss' && !empty($module)) setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors'); } } + if ($dirins && $action == 'initjs' && !empty($module)) { dol_mkdir($dirins.'/'.strtolower($module).'/js'); @@ -1567,14 +1568,26 @@ $infomodulesfound = '
'.$form->textwithpicto( $error = 0; $moduleobj = null; + + if (!empty($module) && $module != 'initmodule' && $module != 'deletemodule') { $modulelowercase = strtolower($module); + $loadclasserrormessage = ''; // Load module - $fullpathdirtodescriptor = $listofmodules[strtolower($module)]['moduledescriptorrelpath']; - dol_include_once($fullpathdirtodescriptor); - $class = 'mod'.$module; + try { + $fullpathdirtodescriptor = $listofmodules[strtolower($module)]['moduledescriptorrelpath']; + + //throw(new Exception()); + dol_include_once($fullpathdirtodescriptor); + + $class = 'mod'.$module; + } catch(Throwable $e) { // This is called in PHP 7 only. Never call be keep rest of code ok with PHP 5.6 + $loadclasserrormessage = $e->getMessage()."
\n";; + $loadclasserrormessage .= 'File: '.$e->getFile()."
\n"; + $loadclasserrormessage .= 'Line: '.$e->getLine()."
\n"; + } if (class_exists($class)) { @@ -1589,6 +1602,7 @@ if (!empty($module) && $module != 'initmodule' && $module != 'deletemodule') if (empty($forceddirread)) $error++; $langs->load("errors"); print img_warning('').' '.$langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module).'
'; + print $loadclasserrormessage; } } @@ -1620,7 +1634,7 @@ if (is_array($listofmodules) && count($listofmodules) > 0) { $urltomodulesetup = ''.$langs->trans('Home').'-'.$langs->trans("Setup").'-'.$langs->trans("Modules").''; if (!empty($conf->global->$const_name)) // If module is already activated { - $linktoenabledisable .= ''; + $linktoenabledisable .= ''; $linktoenabledisable .= img_picto($langs->trans("Activated"), 'switch_on', '', false, 0, 0, '', '', 1); $linktoenabledisable .= ''; @@ -1656,7 +1670,7 @@ if (is_array($listofmodules) && count($listofmodules) > 0) { $linktoenabledisable .= '   '.img_picto($langs->trans("Setup"), "setup", 'style="padding-right: 6px"').''; } } else { - $linktoenabledisable .= ''; + $linktoenabledisable .= ''; $linktoenabledisable .= img_picto($langs->trans("ModuleIsNotActive", $urltomodulesetup), 'switch_off', '', false, 0, 0, '', 'classfortooltip', 1); $linktoenabledisable .= "\n"; }