From b5e6dec0c6eaf1f3ce45ac0dc29cb29261a69e7e Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 6 Dec 2022 14:06:08 +0000 Subject: [PATCH] Filesystem: capture error information from attempted lock file creation --- src/utils/Filesystem.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utils/Filesystem.php b/src/utils/Filesystem.php index a4c1ff236..0a183d4cd 100644 --- a/src/utils/Filesystem.php +++ b/src/utils/Filesystem.php @@ -187,9 +187,10 @@ final class Filesystem{ * @throws \InvalidArgumentException if the lock file path is invalid (e.g. parent directory doesn't exist, permission denied) */ public static function createLockFile(string $lockFilePath) : ?int{ - $resource = fopen($lockFilePath, "a+b"); - if($resource === false){ - throw new \InvalidArgumentException("Invalid lock file path or read/write permissions denied"); + try{ + $resource = ErrorToExceptionHandler::trapAndRemoveFalse(fn() => fopen($lockFilePath, "a+b")); + }catch(\ErrorException $e){ + throw new \InvalidArgumentException("Failed to open lock file: " . $e->getMessage(), 0, $e); } if(!flock($resource, LOCK_EX | LOCK_NB)){ //wait for a shared lock to avoid race conditions if two servers started at the same time - this makes sure the