Skip to content

Commit

Permalink
Fixed write false
Browse files Browse the repository at this point in the history
  • Loading branch information
stelin committed Oct 16, 2019
1 parent 2f30071 commit 08c4244
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/framework/src/Co.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/log/src/Handler/FileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,6 +75,7 @@ public function init(): void
* @param array $records
*
* @return void
* @throws SwoftException
*/
public function handleBatch(array $records): void
{
Expand All @@ -90,6 +92,7 @@ public function handleBatch(array $records): void
*
* @param array $records
*
* @throws SwoftException
*/
protected function write(array $records): void
{
Expand All @@ -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)
Expand Down

0 comments on commit 08c4244

Please sign in to comment.