mirror of
https://github.com/nextcloud/server.git
synced 2026-04-22 14:50:17 -04:00
Merge pull request #4150 from owncloud/better-error-handling
Better error handling
This commit is contained in:
commit
f7422ad132
6 changed files with 42 additions and 41 deletions
|
|
@ -839,9 +839,9 @@ class OC_App{
|
|||
OC_Hook::emit('update', 'success', 'Updated '.$info['name'].' app');
|
||||
}
|
||||
catch (Exception $e) {
|
||||
echo 'Failed to upgrade "'.$app.'". Exception="'.$e->getMessage().'"';
|
||||
OC_Hook::emit('update', 'failure', 'Failed to update '.$info['name'].' app: '.$e->getMessage());
|
||||
die;
|
||||
$l = OC_L10N::get('lib');
|
||||
throw new RuntimeException($l->t('Failed to upgrade "%s".', array($app)), 0, $e);
|
||||
}
|
||||
OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app));
|
||||
}
|
||||
|
|
|
|||
10
lib/base.php
10
lib/base.php
|
|
@ -422,9 +422,13 @@ class OC {
|
|||
}
|
||||
}
|
||||
|
||||
if (!defined('PHPUNIT_RUN') and !(defined('DEBUG') and DEBUG)) {
|
||||
OC\Log\ErrorHandler::register();
|
||||
OC\Log\ErrorHandler::setLogger(OC_Log::$object);
|
||||
if (!defined('PHPUNIT_RUN')) {
|
||||
if (defined('DEBUG') and DEBUG) {
|
||||
set_exception_handler(array('OC_Template', 'printExceptionErrorPage'));
|
||||
} else {
|
||||
OC\Log\ErrorHandler::register();
|
||||
OC\Log\ErrorHandler::setLogger(OC_Log::$object);
|
||||
}
|
||||
}
|
||||
|
||||
// register the stream wrappers
|
||||
|
|
|
|||
|
|
@ -62,7 +62,8 @@ class OC_Files {
|
|||
$zip = new ZipArchive();
|
||||
$filename = OC_Helper::tmpFile('.zip');
|
||||
if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)!==true) {
|
||||
exit("cannot open <$filename>\n");
|
||||
$l = OC_L10N::get('lib');
|
||||
throw new Exception($l->t('cannot open "%s"', array($filename)));
|
||||
}
|
||||
foreach ($files as $file) {
|
||||
$file = $dir . '/' . $file;
|
||||
|
|
@ -93,7 +94,8 @@ class OC_Files {
|
|||
$zip = new ZipArchive();
|
||||
$filename = OC_Helper::tmpFile('.zip');
|
||||
if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)!==true) {
|
||||
exit("cannot open <$filename>\n");
|
||||
$l = OC_L10N::get('lib');
|
||||
throw new Exception($l->t('cannot open "%s"', array($filename)));
|
||||
}
|
||||
$file = $dir . '/' . $files;
|
||||
self::zipAddDir($file, $zip);
|
||||
|
|
@ -220,16 +222,11 @@ class OC_Files {
|
|||
if (!OC_Config::getValue('allowZipDownload', true)) {
|
||||
$l = OC_L10N::get('lib');
|
||||
header("HTTP/1.0 409 Conflict");
|
||||
$tmpl = new OC_Template('', 'error', 'user');
|
||||
$errors = array(
|
||||
array(
|
||||
'error' => $l->t('ZIP download is turned off.'),
|
||||
'hint' => $l->t('Files need to be downloaded one by one.')
|
||||
. '<br/><a href="javascript:history.back()">' . $l->t('Back to Files') . '</a>',
|
||||
)
|
||||
OC_Template::printErrorPage(
|
||||
$l->t('ZIP download is turned off.'),
|
||||
$l->t('Files need to be downloaded one by one.')
|
||||
. '<br/><a href="javascript:history.back()">' . $l->t('Back to Files') . '</a>'
|
||||
);
|
||||
$tmpl->assign('errors', $errors);
|
||||
$tmpl->printPage();
|
||||
exit;
|
||||
}
|
||||
|
||||
|
|
@ -252,17 +249,12 @@ class OC_Files {
|
|||
if ($totalsize > $zipLimit) {
|
||||
$l = OC_L10N::get('lib');
|
||||
header("HTTP/1.0 409 Conflict");
|
||||
$tmpl = new OC_Template('', 'error', 'user');
|
||||
$errors = array(
|
||||
array(
|
||||
'error' => $l->t('Selected files too large to generate zip file.'),
|
||||
'hint' => 'Download the files in smaller chunks, seperately'
|
||||
.' or kindly ask your administrator.<br/><a href="javascript:history.back()">'
|
||||
. $l->t('Back to Files') . '</a>',
|
||||
)
|
||||
OC_Template::printErrorPage(
|
||||
$l->t('Selected files too large to generate zip file.'),
|
||||
$l->t('Download the files in smaller chunks, seperately or kindly ask your administrator.')
|
||||
.'<br/><a href="javascript:history.back()">'
|
||||
. $l->t('Back to Files') . '</a>'
|
||||
);
|
||||
$tmpl->assign('errors', $errors);
|
||||
$tmpl->printPage();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -176,8 +176,7 @@ class OC_Helper {
|
|||
}elseif( file_exists( OC::$SERVERROOT."/core/img/$image" )) {
|
||||
return OC::$WEBROOT."/core/img/$image";
|
||||
}else{
|
||||
echo('image not found: image:'.$image.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
|
||||
die();
|
||||
throw new RuntimeException('image not found: image:'.$image.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -185,9 +185,7 @@ class OC_Setup {
|
|||
$hint = $l->t('Please double check the <a href=\'%s\'>installation guides</a>.',
|
||||
'http://doc.owncloud.org/server/5.0/admin_manual/installation.html');
|
||||
|
||||
$tmpl = new OC_Template('', 'error', 'guest');
|
||||
$tmpl->assign('errors', array(1 => array('error' => $error, 'hint' => $hint)));
|
||||
$tmpl->printPage();
|
||||
OC_Template::printErrorPage($error, $hint);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -531,17 +531,25 @@ class OC_Template{
|
|||
if ($exception->getCode()) {
|
||||
$error_msg = '['.$exception->getCode().'] '.$error_msg;
|
||||
}
|
||||
$hint = $exception->getTraceAsString();
|
||||
if (!empty($hint)) {
|
||||
$hint = '<pre>'.$hint.'</pre>';
|
||||
}
|
||||
while (method_exists($exception,'previous') && $exception = $exception->previous()) {
|
||||
$error_msg .= '<br/>Caused by: ';
|
||||
if ($exception->getCode()) {
|
||||
$error_msg .= '['.$exception->getCode().'] ';
|
||||
if (defined('DEBUG') and DEBUG) {
|
||||
$hint = $exception->getTraceAsString();
|
||||
if (!empty($hint)) {
|
||||
$hint = '<pre>'.$hint.'</pre>';
|
||||
}
|
||||
$error_msg .= $exception->getMessage();
|
||||
};
|
||||
$l = OC_L10N::get('lib');
|
||||
while (method_exists($exception, 'previous') && $exception = $exception->previous()) {
|
||||
$error_msg .= '<br/>'.$l->t('Caused by:').' ';
|
||||
if ($exception->getCode()) {
|
||||
$error_msg .= '['.$exception->getCode().'] ';
|
||||
}
|
||||
$error_msg .= $exception->getMessage();
|
||||
};
|
||||
} else {
|
||||
$hint = '';
|
||||
if ($exception instanceof \OC\HintException) {
|
||||
$hint = $exception->getHint();
|
||||
}
|
||||
}
|
||||
self::printErrorPage($error_msg, $hint);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue