From f8b1552f033db589f0400525e324654cb715261e Mon Sep 17 00:00:00 2001 From: Luke Page Date: Wed, 30 Jan 2019 08:24:05 +0100 Subject: [PATCH] Ignore errors raised by fs.closeSync() As per comments here: https://github.com/npm/write-file-atomic/commit/3365a4df7d6117473905ec3f633d9a1bb42b6b17 Close #38 --- index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 3eef78a..64ae987 100644 --- a/index.js +++ b/index.js @@ -224,7 +224,13 @@ function writeFileSync (filename, data, options) { fs.renameSync(tmpfile, filename) removeOnExitHandler() } catch (err) { - if (fd) fs.closeSync(fd) + if (fd) { + try { + fs.closeSync(fd) + } catch (ex) { + // ignore close errors at this stage, error may have closed fd already. + } + } removeOnExitHandler() cleanup() throw err