From: Roland Häder Date: Tue, 7 Aug 2012 16:23:54 +0000 (+0000) Subject: Now use a try/catch block X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c7eb39a077c5f18ff6582889bf1c06cdfbec8f76;p=hub.git Now use a try/catch block --- diff --git a/application/hub/exceptions/package/class_FinalChunkVerificationException.php b/application/hub/exceptions/package/class_FinalChunkVerificationException.php index 6d6d423c4..5fb73545c 100644 --- a/application/hub/exceptions/package/class_FinalChunkVerificationException.php +++ b/application/hub/exceptions/package/class_FinalChunkVerificationException.php @@ -32,12 +32,13 @@ class FinalChunkVerificationException extends FrameworkException { */ public function __construct (array $messageArray, $code) { // Construct the message - $message = sprintf("[%s:%d] The final chunk %s is not a valid EOP (%s) chunk. Total chunks: %s", + $message = sprintf("[%s:%d] The final chunk %s is not a valid EOP (%s) chunk. Total chunks: %s, cause: %s", $messageArray[0]->__toString(), $this->getLine(), $messageArray[1][count($messageArray[1]) - 1], PackageFragmenter::END_OF_PACKAGE_IDENTIFIER, - count($messageArray[1]) + count($messageArray[1]), + $messageArray[2]->__toString() ); // Call parent exception constructor diff --git a/application/hub/main/class_BaseHubSystem.php b/application/hub/main/class_BaseHubSystem.php index 9d84ce9ba..3d0db1f6a 100644 --- a/application/hub/main/class_BaseHubSystem.php +++ b/application/hub/main/class_BaseHubSystem.php @@ -450,7 +450,7 @@ class BaseHubSystem extends BaseFrameworkSystem { $chunkSplits = explode(PackageFragmenter::CHUNK_DATA_HASH_SEPARATOR, $chunks[count($chunks) - 1]); // Make sure chunks with only 3 elements are parsed (for details see ChunkHandler) - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('eopChunk=' . $chunks[count($chunks) - 1] . ',chunkSplits=' . print_r($chunkSplits,true)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('eopChunk=' . $chunks[count($chunks) - 1] . ',chunkSplits=' . print_r($chunkSplits, true)); assert(count($chunkSplits) == 3); // Validate final chunk diff --git a/application/hub/main/handler/chunks/class_ChunkHandler.php b/application/hub/main/handler/chunks/class_ChunkHandler.php index 739e07e24..e8b104ad0 100644 --- a/application/hub/main/handler/chunks/class_ChunkHandler.php +++ b/application/hub/main/handler/chunks/class_ChunkHandler.php @@ -358,11 +358,14 @@ class ChunkHandler extends BaseHandler implements HandleableChunks, Registerable * @throws FinalChunkVerificationException If the final chunk does not start with 'EOP:' */ public function addAllChunksWithFinal (array $chunks) { - // Validate final chunk - if (!$this->isValidFinalChunk($chunks)) { + // Try to validate the final chunk + try { + // Validate final chunk + $this->isValidFinalChunk($chunks); + } catch (AssertionException $e) { // Last chunk is not valid - throw new FinalChunkVerificationException(array($this, $chunks), BaseListener::EXCEPTION_FINAL_CHUNK_VERIFICATION); - } // END - if + throw new FinalChunkVerificationException(array($this, $chunks, $e), BaseListener::EXCEPTION_FINAL_CHUNK_VERIFICATION); + } // Do we have some pending chunks (no final)? while (!$this->getStackerInstance()->isStackEmpty(self::STACKER_NAME_CHUNKS_WITHOUT_FINAL)) {