Skip to content

Commit

Permalink
fs: do not call new when creating uvException
Browse files Browse the repository at this point in the history
We cannot make uvException a proper class due to compatibility
reasons for now, so there is no need to call new since
it only returns a newly-created Error.

PR-URL: #18546
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
joyeecheung committed Feb 7, 2018
1 parent 12ae334 commit 0303848
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ fs.accessSync = function(path, mode) {
binding.access(pathModule.toNamespacedPath(path), mode, undefined, ctx);

if (ctx.errno !== undefined) {
throw new errors.uvException(ctx);
throw errors.uvException(ctx);
}
};

Expand Down Expand Up @@ -638,7 +638,7 @@ function tryStatSync(fd, isUserFd) {
binding.fstat(fd, undefined, ctx);
if (ctx.errno !== undefined && !isUserFd) {
fs.closeSync(fd);
throw new errors.uvException(ctx);
throw errors.uvException(ctx);
}
}

Expand Down Expand Up @@ -736,7 +736,7 @@ fs.closeSync = function(fd) {
const ctx = {};
binding.close(fd, undefined, ctx);
if (ctx.errno !== undefined) {
throw new errors.uvException(ctx);
throw errors.uvException(ctx);
}
};

Expand Down Expand Up @@ -929,7 +929,7 @@ fs.renameSync = function(oldPath, newPath) {
binding.rename(pathModule.toNamespacedPath(oldPath),
pathModule.toNamespacedPath(newPath), undefined, ctx);
if (ctx.errno !== undefined) {
throw new errors.uvException(ctx);
throw errors.uvException(ctx);
}
};

Expand Down Expand Up @@ -999,7 +999,7 @@ fs.ftruncateSync = function(fd, len = 0) {
const ctx = {};
binding.ftruncate(fd, len, undefined, ctx);
if (ctx.errno !== undefined) {
throw new errors.uvException(ctx);
throw errors.uvException(ctx);
}
};

Expand Down Expand Up @@ -1033,7 +1033,7 @@ fs.fdatasyncSync = function(fd) {
const ctx = {};
binding.fdatasync(fd, undefined, ctx);
if (ctx.errno !== undefined) {
throw new errors.uvException(ctx);
throw errors.uvException(ctx);
}
};

Expand All @@ -1049,7 +1049,7 @@ fs.fsyncSync = function(fd) {
const ctx = {};
binding.fsync(fd, undefined, ctx);
if (ctx.errno !== undefined) {
throw new errors.uvException(ctx);
throw errors.uvException(ctx);
}
};

Expand Down Expand Up @@ -1134,7 +1134,7 @@ fs.fstatSync = function(fd) {
const ctx = { fd };
binding.fstat(fd, undefined, ctx);
if (ctx.errno !== undefined) {
throw new errors.uvException(ctx);
throw errors.uvException(ctx);
}
return statsFromValues();
};
Expand All @@ -1146,7 +1146,7 @@ fs.lstatSync = function(path) {
const ctx = { path };
binding.lstat(pathModule.toNamespacedPath(path), undefined, ctx);
if (ctx.errno !== undefined) {
throw new errors.uvException(ctx);
throw errors.uvException(ctx);
}
return statsFromValues();
};
Expand All @@ -1158,7 +1158,7 @@ fs.statSync = function(path) {
const ctx = { path };
binding.stat(pathModule.toNamespacedPath(path), undefined, ctx);
if (ctx.errno !== undefined) {
throw new errors.uvException(ctx);
throw errors.uvException(ctx);
}
return statsFromValues();
};
Expand All @@ -1184,7 +1184,7 @@ fs.readlinkSync = function(path, options) {
const result = binding.readlink(pathModule.toNamespacedPath(path),
options.encoding, undefined, ctx);
if (ctx.errno !== undefined) {
throw new errors.uvException(ctx);
throw errors.uvException(ctx);
}
return result;
};
Expand Down Expand Up @@ -1264,7 +1264,7 @@ fs.symlinkSync = function(target, path, type) {
pathModule.toNamespacedPath(path), flags, undefined, ctx);

if (ctx.errno !== undefined) {
throw new errors.uvException(ctx);
throw errors.uvException(ctx);
} else if (ctx.error) {
// TODO(joyeecheung): this is an encoding error usually caused by memory
// problems. We need to figure out proper error code(s) for this.
Expand Down Expand Up @@ -1309,7 +1309,7 @@ fs.linkSync = function(existingPath, newPath) {
pathModule.toNamespacedPath(newPath),
undefined, ctx);
if (ctx.errno !== undefined) {
throw new errors.uvException(ctx);
throw errors.uvException(ctx);
}
return result;
};
Expand All @@ -1332,7 +1332,7 @@ fs.unlinkSync = function(path) {
const ctx = { path };
binding.unlink(pathModule.toNamespacedPath(path), undefined, ctx);
if (ctx.errno !== undefined) {
throw new errors.uvException(ctx);
throw errors.uvException(ctx);
}
};

Expand Down Expand Up @@ -1939,7 +1939,7 @@ fs.realpathSync = function realpathSync(p, options) {
const ctx = { path: base };
binding.lstat(pathModule.toNamespacedPath(base), undefined, ctx);
if (ctx.errno !== undefined) {
throw new errors.uvException(ctx);
throw errors.uvException(ctx);
}
knownHard[base] = true;
}
Expand Down Expand Up @@ -1983,7 +1983,7 @@ fs.realpathSync = function realpathSync(p, options) {
const ctx = { path: base };
binding.lstat(baseLong, undefined, ctx);
if (ctx.errno !== undefined) {
throw new errors.uvException(ctx);
throw errors.uvException(ctx);
}

if ((statValues[1/*mode*/] & S_IFMT) !== S_IFLNK) {
Expand All @@ -2008,11 +2008,11 @@ fs.realpathSync = function realpathSync(p, options) {
const ctx = { path: base };
binding.stat(baseLong, undefined, ctx);
if (ctx.errno !== undefined) {
throw new errors.uvException(ctx);
throw errors.uvException(ctx);
}
linkTarget = binding.readlink(baseLong, undefined, undefined, ctx);
if (ctx.errno !== undefined) {
throw new errors.uvException(ctx);
throw errors.uvException(ctx);
}
}
resolvedLink = pathModule.resolve(previous, linkTarget);
Expand All @@ -2033,7 +2033,7 @@ fs.realpathSync = function realpathSync(p, options) {
const ctx = { path: base };
binding.lstat(pathModule.toNamespacedPath(base), undefined, ctx);
if (ctx.errno !== undefined) {
throw new errors.uvException(ctx);
throw errors.uvException(ctx);
}
knownHard[base] = true;
}
Expand Down

0 comments on commit 0303848

Please sign in to comment.