node/test/parallel/test-fs-non-number-arguments-throw.js
matzavinos 219932a9f7
errors: convert 'fs'
covert lib/fs.js over to using lib/internal/errors.js
i have not addressed the cases that use errnoException(),
for reasons described in GH-12926

- throw the ERR_INVALID_CALLBACK error
  when the the callback is invalid
- replace the ['object', 'string'] with
  ['string', 'object'] in the error constructor call,
  to better match the previous err msg
  in the getOptions() function
- add error ERR_VALUE_OUT_OF_RANGE in lib/internal/errors.js,
  this error is thrown when a numeric value is out of range
- document the ERR_VALUE_OUT_OF_RANGE err in errors.md
- correct the expected args, in the error thrown in the function
  fs._toUnixTimestamp() to ['Date', 'time in seconds'] (lib/fs.js)
- update the listener error type in the fs.watchFile() function,
  from Error to TypeError (lib/fs.js)
- update errors from ERR_INVALID_OPT_VALUE to ERR_INVALID_ARG_TYPE
  in the functions fs.ReadStream() and fs.WriteStream(),
  for the cases of range errors use the new error:
  ERR_VALUE_OUT_OF_RANGE (lib/fs.js)

PR-URL: https://github.com/nodejs/node/pull/15043
Refs: https://github.com/nodejs/node/issues/11273
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2017-08-31 19:37:39 -04:00

48 lines
1.1 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const tempFile = path.join(common.tmpDir, 'fs-non-number-arguments-throw');
common.refreshTmpDir();
fs.writeFileSync(tempFile, 'abc\ndef');
// a sanity check when using numbers instead of strings
const sanity = 'def';
const saneEmitter = fs.createReadStream(tempFile, { start: 4, end: 6 });
common.expectsError(
() => {
fs.createReadStream(tempFile, { start: '4', end: 6 });
},
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError
});
common.expectsError(
() => {
fs.createReadStream(tempFile, { start: 4, end: '6' });
},
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError
});
common.expectsError(
() => {
fs.createWriteStream(tempFile, { start: '4' });
},
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError
});
saneEmitter.on('data', common.mustCall(function(data) {
assert.strictEqual(
sanity, data.toString('utf8'),
`read ${data.toString('utf8')} instead of ${sanity}`);
}));