Skip to content

Commit 14ddb52

Browse files
committed
Fixes #115
1 parent 42cd5f7 commit 14ddb52

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

lib/tmp.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ function _prepareTmpFileRemoveCallback(name, fd, opts) {
375375
// under some node/windows related circumstances, a temporary file
376376
// may have not be created as expected or the file was already closed
377377
// by the user, in which case we will simply ignore the error
378-
if (e.errno != -EBADF && e.errno != -ENOENT) {
378+
if (!isEBADF(e) && !isENOENT(e)) {
379379
// reraise any unanticipated error
380380
throw e;
381381
}
@@ -456,6 +456,44 @@ function _garbageCollector() {
456456
}
457457
}
458458

459+
/**
460+
* Helper for testing against EBADF to compensate changes made to Node 7.x under Windows.
461+
*/
462+
function isEBADF(error) {
463+
return isExpectedError(error, -EBADF, 'EBADF');
464+
}
465+
466+
/**
467+
* Helper for testing against ENOENT to compensate changes made to Node 7.x under Windows.
468+
*/
469+
function isENOENT(error) {
470+
return isExpectedError(error, -EBADF, 'EBADF');
471+
}
472+
473+
/**
474+
* Helper to determine whether the expected error code and errno match the actual code and errno,
475+
* which will differ between the supported node versions.
476+
*
477+
* - Node >= 7.0:
478+
* error.code {String}
479+
* error.errno {String|Number} any numerical value will be negated
480+
*
481+
* - Node >= 6.0 < 7.0:
482+
* error.code {String}
483+
* error.errno {Number} negated
484+
*
485+
* - Node >= 4.0 < 6.0: introduces SystemError
486+
* error.code {String}
487+
* error.errno {Number} negated
488+
*
489+
* - Node >= 0.10 < 4.0:
490+
* error.code {Number} negated
491+
* error.errno n/a
492+
*/
493+
function isExpectedError(error, code, errno) {
494+
return error.code == code || error.code == errno;
495+
}
496+
459497
/**
460498
* Sets the graceful cleanup.
461499
*

0 commit comments

Comments
 (0)