Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ddc5532
zlib: port errors to new system
targos Feb 27, 2018
def3846
vm: port errors to new system
targos Feb 27, 2018
c0d20ba
v8: port errors to new system
targos Feb 27, 2018
b08cf46
util: port errors to new system
targos Feb 27, 2018
4a314e7
url: port errors to new system
targos Feb 27, 2018
247ddb8
tty: port errors to new system
targos Feb 27, 2018
870cdf0
tls: port: errors to new system
targos Feb 27, 2018
a7aa7bd
timers: port errors to new system
targos Feb 27, 2018
f350861
string_decoder: port errors to new system
targos Feb 27, 2018
82a4d20
repl: port errors to new system
targos Feb 27, 2018
fa70791
readline: port errors to new system
targos Feb 27, 2018
721314e
querystring: port errors to new system
targos Feb 27, 2018
a7df2bc
perf_hooks: port errors to new system
targos Feb 27, 2018
bda8874
path: port errors to new system
targos Feb 27, 2018
530f289
net: port errors to new system
targos Feb 27, 2018
ac2c9c3
module: port errors to new system
targos Feb 27, 2018
d102090
inspector: port errors to new system
targos Feb 27, 2018
0db60be
https: port errors to new system
targos Feb 27, 2018
a6b8a25
fs: port errors to new system
targos Feb 27, 2018
0b226fd
events: port errors to new system
targos Feb 27, 2018
ee6945c
domain: port errors to new system
targos Feb 27, 2018
5eaffd2
dns: port errors to new system
targos Feb 27, 2018
eabb4f6
dgram: port errors to new system
targos Feb 27, 2018
7d14db2
crypto: port errors to new system
targos Feb 27, 2018
e78c0f9
child_process: port errors to new system
targos Feb 27, 2018
bee022b
buffer: port errors to new system
targos Feb 27, 2018
eccd4b0
async_hooks: port errors to new system
targos Feb 27, 2018
dbddf7b
assert: port errors to new system
targos Feb 27, 2018
0d5b4b9
FIXUP: linter
targos Mar 4, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fs: port errors to new system
  • Loading branch information
targos committed Mar 4, 2018
commit a6b8a2587e9df6a5a3e6cdc7ed3e8615cc4138fb
62 changes: 20 additions & 42 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ const binding = process.binding('fs');
const fs = exports;
const { Buffer } = require('buffer');
const errors = require('internal/errors');
const {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_CALLBACK,
ERR_OUT_OF_RANGE
} = errors.codes;
const { Readable, Writable } = require('stream');
const EventEmitter = require('events');
const { FSReqWrap, statValues } = binding;
Expand Down Expand Up @@ -109,15 +114,15 @@ function maybeCallback(cb) {
if (typeof cb === 'function')
return cb;

throw new errors.TypeError('ERR_INVALID_CALLBACK');
throw new ERR_INVALID_CALLBACK();
}

// Ensure that callbacks run in the global context. Only use this function
// for callbacks that are passed to the binding layer, callbacks that are
// invoked from JS already run in the proper scope.
function makeCallback(cb) {
if (typeof cb !== 'function') {
throw new errors.TypeError('ERR_INVALID_CALLBACK');
throw new ERR_INVALID_CALLBACK();
}

return function(...args) {
Expand All @@ -130,7 +135,7 @@ function makeCallback(cb) {
// transformed anyway.
function makeStatsCallback(cb) {
if (typeof cb !== 'function') {
throw new errors.TypeError('ERR_INVALID_CALLBACK');
throw new ERR_INVALID_CALLBACK();
}

return function(err) {
Expand Down Expand Up @@ -1000,7 +1005,7 @@ fs.fchmod = function(fd, mode, callback) {
validateUint32(mode, 'mode');
// values for mode < 0 are already checked via the validateUint32 function
if (mode > 0o777)
throw new errors.RangeError('ERR_OUT_OF_RANGE', 'mode');
throw new ERR_OUT_OF_RANGE('mode');

const req = new FSReqWrap();
req.oncomplete = makeCallback(callback);
Expand All @@ -1012,7 +1017,7 @@ fs.fchmodSync = function(fd, mode) {
validateUint32(fd, 'fd');
validateUint32(mode, 'mode');
if (mode < 0 || mode > 0o777)
throw new errors.RangeError('ERR_OUT_OF_RANGE', 'mode');
throw new ERR_OUT_OF_RANGE('mode');
const ctx = {};
binding.fchmod(fd, mode, undefined, ctx);
handleErrorFromBinding(ctx);
Expand Down Expand Up @@ -1457,10 +1462,7 @@ fs.watchFile = function(filename, options, listener) {
}

if (typeof listener !== 'function') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'listener',
'Function',
listener);
throw new ERR_INVALID_ARG_TYPE('listener', 'Function', listener);
}

stat = statWatchers.get(filename);
Expand Down Expand Up @@ -1835,10 +1837,7 @@ fs.mkdtemp = function(prefix, options, callback) {
callback = makeCallback(typeof options === 'function' ? options : callback);
options = getOptions(options, {});
if (!prefix || typeof prefix !== 'string') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'prefix',
'string',
prefix);
throw new ERR_INVALID_ARG_TYPE('prefix', 'string', prefix);
}
nullCheck(prefix, 'prefix');
var req = new FSReqWrap();
Expand All @@ -1850,10 +1849,7 @@ fs.mkdtemp = function(prefix, options, callback) {
fs.mkdtempSync = function(prefix, options) {
options = getOptions(options, {});
if (!prefix || typeof prefix !== 'string') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'prefix',
'string',
prefix);
throw new ERR_INVALID_ARG_TYPE('prefix', 'string', prefix);
}
nullCheck(prefix, 'prefix');
const path = `${prefix}XXXXXX`;
Expand All @@ -1876,7 +1872,7 @@ fs.copyFile = function(src, dest, flags, callback) {
callback = flags;
flags = 0;
} else if (typeof callback !== 'function') {
throw new errors.TypeError('ERR_INVALID_CALLBACK');
throw new ERR_INVALID_CALLBACK();
}

src = getPathFromURL(src);
Expand Down Expand Up @@ -1951,26 +1947,17 @@ function ReadStream(path, options) {

if (this.start !== undefined) {
if (typeof this.start !== 'number') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'start',
'number',
this.start);
throw new ERR_INVALID_ARG_TYPE('start', 'number', this.start);
}
if (this.end === undefined) {
this.end = Infinity;
} else if (typeof this.end !== 'number') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'end',
'number',
this.end);
throw new ERR_INVALID_ARG_TYPE('end', 'number', this.end);
}

if (this.start > this.end) {
const errVal = `{start: ${this.start}, end: ${this.end}}`;
throw new errors.RangeError('ERR_OUT_OF_RANGE',
'start',
'<= "end"',
errVal);
throw new ERR_OUT_OF_RANGE('start', '<= "end"', errVal);
}

this.pos = this.start;
Expand Down Expand Up @@ -2113,17 +2100,11 @@ function WriteStream(path, options) {

if (this.start !== undefined) {
if (typeof this.start !== 'number') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'start',
'number',
this.start);
throw new ERR_INVALID_ARG_TYPE('start', 'number', this.start);
}
if (this.start < 0) {
const errVal = `{start: ${this.start}}`;
throw new errors.RangeError('ERR_OUT_OF_RANGE',
'start',
'>= 0',
errVal);
throw new ERR_OUT_OF_RANGE('start', '>= 0', errVal);
}

this.pos = this.start;
Expand Down Expand Up @@ -2164,10 +2145,7 @@ WriteStream.prototype.open = function() {

WriteStream.prototype._write = function(data, encoding, cb) {
if (!(data instanceof Buffer)) {
const err = new errors.TypeError('ERR_INVALID_ARG_TYPE',
'data',
'Buffer',
data);
const err = new ERR_INVALID_ARG_TYPE('data', 'Buffer', data);
return this.emit('error', err);
}

Expand Down