fs: do not call new when creating uvException
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: https://github.com/nodejs/node/pull/18546 Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
12ae33476a
commit
030384833f
38
lib/fs.js
38
lib/fs.js
@ -407,7 +407,7 @@ fs.accessSync = function(path, mode) {
|
|||||||
binding.access(pathModule.toNamespacedPath(path), mode, undefined, ctx);
|
binding.access(pathModule.toNamespacedPath(path), mode, undefined, ctx);
|
||||||
|
|
||||||
if (ctx.errno !== undefined) {
|
if (ctx.errno !== undefined) {
|
||||||
throw new errors.uvException(ctx);
|
throw errors.uvException(ctx);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -638,7 +638,7 @@ function tryStatSync(fd, isUserFd) {
|
|||||||
binding.fstat(fd, undefined, ctx);
|
binding.fstat(fd, undefined, ctx);
|
||||||
if (ctx.errno !== undefined && !isUserFd) {
|
if (ctx.errno !== undefined && !isUserFd) {
|
||||||
fs.closeSync(fd);
|
fs.closeSync(fd);
|
||||||
throw new errors.uvException(ctx);
|
throw errors.uvException(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -736,7 +736,7 @@ fs.closeSync = function(fd) {
|
|||||||
const ctx = {};
|
const ctx = {};
|
||||||
binding.close(fd, undefined, ctx);
|
binding.close(fd, undefined, ctx);
|
||||||
if (ctx.errno !== undefined) {
|
if (ctx.errno !== undefined) {
|
||||||
throw new errors.uvException(ctx);
|
throw errors.uvException(ctx);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -929,7 +929,7 @@ fs.renameSync = function(oldPath, newPath) {
|
|||||||
binding.rename(pathModule.toNamespacedPath(oldPath),
|
binding.rename(pathModule.toNamespacedPath(oldPath),
|
||||||
pathModule.toNamespacedPath(newPath), undefined, ctx);
|
pathModule.toNamespacedPath(newPath), undefined, ctx);
|
||||||
if (ctx.errno !== undefined) {
|
if (ctx.errno !== undefined) {
|
||||||
throw new errors.uvException(ctx);
|
throw errors.uvException(ctx);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -999,7 +999,7 @@ fs.ftruncateSync = function(fd, len = 0) {
|
|||||||
const ctx = {};
|
const ctx = {};
|
||||||
binding.ftruncate(fd, len, undefined, ctx);
|
binding.ftruncate(fd, len, undefined, ctx);
|
||||||
if (ctx.errno !== undefined) {
|
if (ctx.errno !== undefined) {
|
||||||
throw new errors.uvException(ctx);
|
throw errors.uvException(ctx);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1033,7 +1033,7 @@ fs.fdatasyncSync = function(fd) {
|
|||||||
const ctx = {};
|
const ctx = {};
|
||||||
binding.fdatasync(fd, undefined, ctx);
|
binding.fdatasync(fd, undefined, ctx);
|
||||||
if (ctx.errno !== undefined) {
|
if (ctx.errno !== undefined) {
|
||||||
throw new errors.uvException(ctx);
|
throw errors.uvException(ctx);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1049,7 +1049,7 @@ fs.fsyncSync = function(fd) {
|
|||||||
const ctx = {};
|
const ctx = {};
|
||||||
binding.fsync(fd, undefined, ctx);
|
binding.fsync(fd, undefined, ctx);
|
||||||
if (ctx.errno !== undefined) {
|
if (ctx.errno !== undefined) {
|
||||||
throw new errors.uvException(ctx);
|
throw errors.uvException(ctx);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1134,7 +1134,7 @@ fs.fstatSync = function(fd) {
|
|||||||
const ctx = { fd };
|
const ctx = { fd };
|
||||||
binding.fstat(fd, undefined, ctx);
|
binding.fstat(fd, undefined, ctx);
|
||||||
if (ctx.errno !== undefined) {
|
if (ctx.errno !== undefined) {
|
||||||
throw new errors.uvException(ctx);
|
throw errors.uvException(ctx);
|
||||||
}
|
}
|
||||||
return statsFromValues();
|
return statsFromValues();
|
||||||
};
|
};
|
||||||
@ -1146,7 +1146,7 @@ fs.lstatSync = function(path) {
|
|||||||
const ctx = { path };
|
const ctx = { path };
|
||||||
binding.lstat(pathModule.toNamespacedPath(path), undefined, ctx);
|
binding.lstat(pathModule.toNamespacedPath(path), undefined, ctx);
|
||||||
if (ctx.errno !== undefined) {
|
if (ctx.errno !== undefined) {
|
||||||
throw new errors.uvException(ctx);
|
throw errors.uvException(ctx);
|
||||||
}
|
}
|
||||||
return statsFromValues();
|
return statsFromValues();
|
||||||
};
|
};
|
||||||
@ -1158,7 +1158,7 @@ fs.statSync = function(path) {
|
|||||||
const ctx = { path };
|
const ctx = { path };
|
||||||
binding.stat(pathModule.toNamespacedPath(path), undefined, ctx);
|
binding.stat(pathModule.toNamespacedPath(path), undefined, ctx);
|
||||||
if (ctx.errno !== undefined) {
|
if (ctx.errno !== undefined) {
|
||||||
throw new errors.uvException(ctx);
|
throw errors.uvException(ctx);
|
||||||
}
|
}
|
||||||
return statsFromValues();
|
return statsFromValues();
|
||||||
};
|
};
|
||||||
@ -1184,7 +1184,7 @@ fs.readlinkSync = function(path, options) {
|
|||||||
const result = binding.readlink(pathModule.toNamespacedPath(path),
|
const result = binding.readlink(pathModule.toNamespacedPath(path),
|
||||||
options.encoding, undefined, ctx);
|
options.encoding, undefined, ctx);
|
||||||
if (ctx.errno !== undefined) {
|
if (ctx.errno !== undefined) {
|
||||||
throw new errors.uvException(ctx);
|
throw errors.uvException(ctx);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
@ -1264,7 +1264,7 @@ fs.symlinkSync = function(target, path, type) {
|
|||||||
pathModule.toNamespacedPath(path), flags, undefined, ctx);
|
pathModule.toNamespacedPath(path), flags, undefined, ctx);
|
||||||
|
|
||||||
if (ctx.errno !== undefined) {
|
if (ctx.errno !== undefined) {
|
||||||
throw new errors.uvException(ctx);
|
throw errors.uvException(ctx);
|
||||||
} else if (ctx.error) {
|
} else if (ctx.error) {
|
||||||
// TODO(joyeecheung): this is an encoding error usually caused by memory
|
// TODO(joyeecheung): this is an encoding error usually caused by memory
|
||||||
// problems. We need to figure out proper error code(s) for this.
|
// problems. We need to figure out proper error code(s) for this.
|
||||||
@ -1309,7 +1309,7 @@ fs.linkSync = function(existingPath, newPath) {
|
|||||||
pathModule.toNamespacedPath(newPath),
|
pathModule.toNamespacedPath(newPath),
|
||||||
undefined, ctx);
|
undefined, ctx);
|
||||||
if (ctx.errno !== undefined) {
|
if (ctx.errno !== undefined) {
|
||||||
throw new errors.uvException(ctx);
|
throw errors.uvException(ctx);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
@ -1332,7 +1332,7 @@ fs.unlinkSync = function(path) {
|
|||||||
const ctx = { path };
|
const ctx = { path };
|
||||||
binding.unlink(pathModule.toNamespacedPath(path), undefined, ctx);
|
binding.unlink(pathModule.toNamespacedPath(path), undefined, ctx);
|
||||||
if (ctx.errno !== undefined) {
|
if (ctx.errno !== undefined) {
|
||||||
throw new errors.uvException(ctx);
|
throw errors.uvException(ctx);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1939,7 +1939,7 @@ fs.realpathSync = function realpathSync(p, options) {
|
|||||||
const ctx = { path: base };
|
const ctx = { path: base };
|
||||||
binding.lstat(pathModule.toNamespacedPath(base), undefined, ctx);
|
binding.lstat(pathModule.toNamespacedPath(base), undefined, ctx);
|
||||||
if (ctx.errno !== undefined) {
|
if (ctx.errno !== undefined) {
|
||||||
throw new errors.uvException(ctx);
|
throw errors.uvException(ctx);
|
||||||
}
|
}
|
||||||
knownHard[base] = true;
|
knownHard[base] = true;
|
||||||
}
|
}
|
||||||
@ -1983,7 +1983,7 @@ fs.realpathSync = function realpathSync(p, options) {
|
|||||||
const ctx = { path: base };
|
const ctx = { path: base };
|
||||||
binding.lstat(baseLong, undefined, ctx);
|
binding.lstat(baseLong, undefined, ctx);
|
||||||
if (ctx.errno !== undefined) {
|
if (ctx.errno !== undefined) {
|
||||||
throw new errors.uvException(ctx);
|
throw errors.uvException(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((statValues[1/*mode*/] & S_IFMT) !== S_IFLNK) {
|
if ((statValues[1/*mode*/] & S_IFMT) !== S_IFLNK) {
|
||||||
@ -2008,11 +2008,11 @@ fs.realpathSync = function realpathSync(p, options) {
|
|||||||
const ctx = { path: base };
|
const ctx = { path: base };
|
||||||
binding.stat(baseLong, undefined, ctx);
|
binding.stat(baseLong, undefined, ctx);
|
||||||
if (ctx.errno !== undefined) {
|
if (ctx.errno !== undefined) {
|
||||||
throw new errors.uvException(ctx);
|
throw errors.uvException(ctx);
|
||||||
}
|
}
|
||||||
linkTarget = binding.readlink(baseLong, undefined, undefined, ctx);
|
linkTarget = binding.readlink(baseLong, undefined, undefined, ctx);
|
||||||
if (ctx.errno !== undefined) {
|
if (ctx.errno !== undefined) {
|
||||||
throw new errors.uvException(ctx);
|
throw errors.uvException(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resolvedLink = pathModule.resolve(previous, linkTarget);
|
resolvedLink = pathModule.resolve(previous, linkTarget);
|
||||||
@ -2033,7 +2033,7 @@ fs.realpathSync = function realpathSync(p, options) {
|
|||||||
const ctx = { path: base };
|
const ctx = { path: base };
|
||||||
binding.lstat(pathModule.toNamespacedPath(base), undefined, ctx);
|
binding.lstat(pathModule.toNamespacedPath(base), undefined, ctx);
|
||||||
if (ctx.errno !== undefined) {
|
if (ctx.errno !== undefined) {
|
||||||
throw new errors.uvException(ctx);
|
throw errors.uvException(ctx);
|
||||||
}
|
}
|
||||||
knownHard[base] = true;
|
knownHard[base] = true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user