Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Try to make a better error reporting when exception fails because res…
Browse files Browse the repository at this point in the history
…ponse already sent or logger fails.

Revert sending the clear cache operation as deferred when refreshing load node info, was breaking get_my_feed as node has a different url once in shutdown scheduler.
  • Loading branch information
cdujeu committed Feb 1, 2017
1 parent 365ffad commit c1ecabe
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 11 deletions.
35 changes: 35 additions & 0 deletions core/src/core/src/pydio/Core/Exception/LoggingException.php
@@ -0,0 +1,35 @@
<?php
/*
* Copyright 2007-2016 Abstrium <contact (at) pydio.com>
* This file is part of Pydio.
*
* Pydio is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pydio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pydio. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <https://pydio.com/>.
*/
namespace Pydio\Core\Exception;

defined('AJXP_EXEC') or die('Access not allowed');

class LoggingException extends PydioException{

/**
* LoggingException constructor.
* @param \Exception $parentException
*/
public function __construct($parentException){
parent::__construct("Error while trying to write to logger: " . $parentException->getMessage());
}

}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright 2007-2016 Abstrium <contact (at) pydio.com>
* This file is part of Pydio.
*
* Pydio is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pydio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pydio. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <https://pydio.com/>.
*/
namespace Pydio\Core\Exception;

defined('AJXP_EXEC') or die('Access not allowed');


class ResponseEmissionException extends PydioException
{
public function __construct(){
parent::__construct("Could not send response!");
}
}
37 changes: 28 additions & 9 deletions core/src/core/src/pydio/Core/Http/Server.php
Expand Up @@ -22,8 +22,10 @@

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Pydio\Core\Exception\LoggingException;
use Pydio\Core\Exception\PydioException;

use Pydio\Core\Exception\ResponseEmissionException;
use Pydio\Core\Http\Message\UserMessage;
use Pydio\Core\Http\Middleware\ITopLevelMiddleware;
use Pydio\Core\Http\Middleware\SapiMiddleware;
Expand Down Expand Up @@ -229,7 +231,11 @@ public function catchError($code, $message, $fichier, $ligne, $context)
if(error_reporting() == 0) {
return ;
}
Logger::error(basename($fichier), "error l.$ligne", array("message" => $message));
try{
Logger::error(basename($fichier), "error l.$ligne", array("message" => $message));
}catch(\Exception $e){
throw new LoggingException($e);
}
if(AJXP_SERVER_DEBUG){
if($context instanceof \Exception){
$message .= $context->getTraceAsString();
Expand All @@ -245,8 +251,12 @@ public function catchError($code, $message, $fichier, $ligne, $context)
}
$resp = $resp->withBody($x);
$x->addChunk(new UserMessage($message, LOG_LEVEL_ERROR));
$this->topMiddleware->emitResponse($req, $resp);

try{
$this->topMiddleware->emitResponse($req, $resp);
}catch(\Exception $e1){
throw new ResponseEmissionException();
}

}

/**
Expand All @@ -262,17 +272,26 @@ public function catchException($exception)
$x = new SerializableResponseStream();
$resp = $resp->withBody($x);
$x->addChunk($exception);
$this->topMiddleware->emitResponse($req, $resp);
try{
$this->topMiddleware->emitResponse($req, $resp);
}catch(\Exception $innerEx){
error_log("Exception thrown while trying to emit a SerizaliableResponseChunk exception!");
}
return;
}

try {
$this->catchError($exception->getCode(), $exception->getMessage(), $exception->getFile(), $exception->getLine(), $exception);
} catch (\Exception $innerEx) {
error_log(get_class($innerEx)." thrown within the exception handler!");
error_log("Original exception was: ".$innerEx->getMessage()." in ".$innerEx->getFile()." on line ".$innerEx->getLine());
error_log("New exception is: ".$innerEx->getMessage()." in ".$innerEx->getFile()." on line ".$innerEx->getLine()." ".$innerEx->getTraceAsString());
print("Error");
} catch (ResponseEmissionException $responseEx){
// Could not send the response, probably because response was already sent. Just log the error, do not try to append content!
error_log("Exception was caught but could not be sent: ".$exception->getMessage());
error_log(" ===> Exception details : ".$exception->getFile()." on line ".$exception->getLine(). " ".$exception->getTraceAsString());

} catch (LoggingException $innerEx) {
error_log($innerEx->getMessage());
error_log("Exception was caught but could not be logged properly: ".$exception->getMessage()." in ".$exception->getFile()." on line ".$exception->getLine());
error_log(" ===> Exception details : ".$exception->getFile()." on line ".$exception->getLine(). " ".$exception->getTraceAsString());
print("Blocking error encountered, please check the server logs: '" . $exception->getMessage()."'");
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/core.cache/CoreCacheLoader.php
Expand Up @@ -110,7 +110,7 @@ public function cacheNodeInfo(&$node, $contextNode, $details){
*/
public function loadNodeInfoFromCache(&$node, $contextNode, $details, $forceRefresh = false){
if($forceRefresh) {
Controller::applyHook("node.clear_cache_deferred", [&$node]);
$this->clearNodeInfoCache($node);
return;
}
if(!$this->enableNodesCaching()) return;
Expand Down
1 change: 0 additions & 1 deletion core/src/plugins/core.cache/manifest.xml
Expand Up @@ -38,7 +38,6 @@
<serverCallback methodName="cacheNodeInfo" hookName="node.info.end"/>
<serverCallback methodName="clearNodeInfoCache" hookName="node.change" defer="true"/>
<serverCallback methodName="clearNodeInfoCache" hookName="node.meta_change" defer="true"/>
<serverCallback methodName="clearNodeInfoCache" hookName="node.clear_cache_deferred" defer="true"/>
<serverCallback methodName="onWorkspaceUpdate" hookName="workspace.after_update" defer="true"/>
<serverCallback methodName="onWorkspaceDelete" hookName="workspace.after_delete" defer="true"/>
</hooks>
Expand Down

0 comments on commit c1ecabe

Please sign in to comment.