diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2017-11-29 12:52:16 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2017-12-28 03:08:25 +0800 |
commit | 9f122e3b5513fd354b3876d06ea322b676b7350d (patch) | |
tree | b833d235a6f3137fda7cd578bdac5d383f3aaf3c /test | |
parent | 6ca10de9468ed027f5e0b45f721d441df5972bc9 (diff) | |
download | android-node-v8-9f122e3b5513fd354b3876d06ea322b676b7350d.tar.gz android-node-v8-9f122e3b5513fd354b3876d06ea322b676b7350d.tar.bz2 android-node-v8-9f122e3b5513fd354b3876d06ea322b676b7350d.zip |
fs: throw fs.close errors in JS
* Collect the error context in both JS and C++, then throw
the error in JS
* Test that the errors thrown from fs.close and fs.closeSync
includes the correct error code, error number and syscall
properties
PR-URL: https://github.com/nodejs/node/pull/17338
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-fs-close-errors.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/parallel/test-fs-close-errors.js b/test/parallel/test-fs-close-errors.js index cadcf2f78c..4f0d31369a 100644 --- a/test/parallel/test-fs-close-errors.js +++ b/test/parallel/test-fs-close-errors.js @@ -1,7 +1,12 @@ 'use strict'; +// This tests that the errors thrown from fs.close and fs.closeSync +// include the desired properties + const common = require('../common'); +const assert = require('assert'); const fs = require('fs'); +const uv = process.binding('uv'); ['', false, null, undefined, {}, []].forEach((i) => { common.expectsError( @@ -21,3 +26,41 @@ const fs = require('fs'); } ); }); + +{ + assert.throws( + () => { + const fd = fs.openSync(__filename, 'r'); + fs.closeSync(fd); + fs.closeSync(fd); + }, + (err) => { + assert.strictEqual(err.code, 'EBADF'); + assert.strictEqual( + err.message, + 'EBADF: bad file descriptor, close' + ); + assert.strictEqual(err.constructor, Error); + assert.strictEqual(err.syscall, 'close'); + assert.strictEqual(err.errno, uv.UV_EBADF); + return true; + } + ); +} + +{ + const fd = fs.openSync(__filename, 'r'); + fs.close(fd, common.mustCall((err) => { + assert.ifError(err); + fs.close(fd, common.mustCall((err) => { + assert.strictEqual(err.code, 'EBADF'); + assert.strictEqual( + err.message, + 'EBADF: bad file descriptor, close' + ); + assert.strictEqual(err.constructor, Error); + assert.strictEqual(err.syscall, 'close'); + assert.strictEqual(err.errno, uv.UV_EBADF); + })); + })); +} |