From ca5f8fc74898ccf1e31a90526b9cac85cbe93e9a Mon Sep 17 00:00:00 2001 From: Gregor MacLennan Date: Thu, 20 Feb 2025 10:46:38 +0000 Subject: [PATCH] fix: catch errors from tryLock() --- index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 5e0ed88..2ce7ab1 100644 --- a/index.js +++ b/index.js @@ -94,8 +94,13 @@ module.exports = class RandomAccessFile extends RandomAccessStorage { // Should we aquire a read lock? const shared = self.mode === RDONLY - if (fsext.tryLock(self.fd, { shared })) onlock(null) - else onlock(createLockError(self.filename)) + try { + const didLock = fsext.tryLock(self.fd, { shared }) + if (didLock) onlock(null) + else onlock(createLockError(self.filename)) + } catch (e) { + onlock(e) + } } function onlock (err) {