summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJörn Friedrich Dreyer <jfd@butonic.de>2013-07-23 08:30:02 -0700
committerJörn Friedrich Dreyer <jfd@butonic.de>2013-07-23 08:30:02 -0700
commitf7422ad132e68c901c5658bbba1bffa626efaa37 (patch)
tree33288dbf526c74130d04a6a29f93fa6675c81765
parentab77af7b4dbb4ae6625f6684bf7d39f2bb48cc81 (diff)
parent179b42c56deeb37cf8c3f782bcd145daac64404b (diff)
downloadnextcloud-server-f7422ad132e68c901c5658bbba1bffa626efaa37.tar.gz
nextcloud-server-f7422ad132e68c901c5658bbba1bffa626efaa37.zip
Merge pull request #4150 from owncloud/better-error-handling
Better error handling
-rw-r--r--lib/app.php4
-rw-r--r--lib/base.php10
-rw-r--r--lib/files.php34
-rw-r--r--lib/helper.php3
-rw-r--r--lib/setup.php4
-rw-r--r--lib/template.php28
6 files changed, 42 insertions, 41 deletions
diff --git a/lib/app.php b/lib/app.php
index baacf508d8e..2437896157a 100644
--- a/lib/app.php
+++ b/lib/app.php
@@ -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));
}
diff --git a/lib/base.php b/lib/base.php
index 1ff462819db..df57fe979f3 100644
--- a/lib/base.php
+++ b/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
diff --git a/lib/files.php b/lib/files.php
index f5dffd970d2..c705d2adb1a 100644
--- a/lib/files.php
+++ b/lib/files.php
@@ -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;
}
}
diff --git a/lib/helper.php b/lib/helper.php
index df0d120976d..ca508e1d933 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -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);
}
}
diff --git a/lib/setup.php b/lib/setup.php
index 59f4cab75de..05a49890976 100644
--- a/lib/setup.php
+++ b/lib/setup.php
@@ -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();
}
}
diff --git a/lib/template.php b/lib/template.php
index d48e3b36821..339b30eb414 100644
--- a/lib/template.php
+++ b/lib/template.php
@@ -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>';
+ }
+ $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();
}
- $error_msg .= $exception->getMessage();
- };
+ }
self::printErrorPage($error_msg, $hint);
}
}