From 08c42449cc5ca7922e5bf54d6523b0d8799ba910 Mon Sep 17 00:00:00 2001 From: stelin <794774870@qq.com> Date: Wed, 16 Oct 2019 15:16:24 +0800 Subject: [PATCH] Fixed write false --- src/framework/src/Co.php | 14 ++++++++++---- src/log/src/Handler/FileHandler.php | 4 +++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/framework/src/Co.php b/src/framework/src/Co.php index bfae63bbf..f2bf81eb5 100644 --- a/src/framework/src/Co.php +++ b/src/framework/src/Co.php @@ -143,15 +143,21 @@ public static function create(callable $callable, bool $wait = true): int /** * Write file * - * @param string $filename - * @param string $data - * @param int|null $flags + * @param string $filename + * @param string $data + * @param int $flags * * @return int + * @throws SwoftException */ public static function writeFile(string $filename, string $data, int $flags = FILE_USE_INCLUDE_PATH): int { - return Coroutine::writeFile($filename, $data, $flags); + $result = Coroutine::writeFile($filename, $data, $flags); + if ($result === false) { + throw new SwoftException(sprintf('Write(%s) file error!', $filename)); + } + + return $result; } /** diff --git a/src/log/src/Handler/FileHandler.php b/src/log/src/Handler/FileHandler.php index 64f74660d..6ae9129d2 100644 --- a/src/log/src/Handler/FileHandler.php +++ b/src/log/src/Handler/FileHandler.php @@ -8,6 +8,7 @@ use InvalidArgumentException; use Monolog\Handler\AbstractProcessingHandler; use Swoft\Co; +use Swoft\Exception\SwoftException; use Swoft\Log\Helper\Log; use Swoft\Log\Logger as SwoftLogger; use Swoft\Log\Logger; @@ -74,6 +75,7 @@ public function init(): void * @param array $records * * @return void + * @throws SwoftException */ public function handleBatch(array $records): void { @@ -90,6 +92,7 @@ public function handleBatch(array $records): void * * @param array $records * + * @throws SwoftException */ protected function write(array $records): void { @@ -106,7 +109,6 @@ protected function write(array $records): void } $res = Co::writeFile($this->logFile, $messageText, FILE_APPEND); - if ($res === false) { throw new InvalidArgumentException( sprintf('Unable to append to log file: %s', $this->logFile)