Skip to content

Commit

Permalink
lib: add comments to empty catch statements
Browse files Browse the repository at this point in the history
PR-URL: nodejs#41831
Backport-PR-URL: nodejs#42160
Refs: https://eslint.org/docs/rules/no-empty
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
Trott authored and danielleadams committed Mar 4, 2022
1 parent 1639379 commit 7bf4fbc
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 19 deletions.
8 changes: 6 additions & 2 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,9 @@ function enhanceStackTrace(err, own) {
const { name } = this.constructor;
if (name !== 'EventEmitter')
ctorInfo = ` on ${name} instance`;
} catch {}
} catch {
// Continue regardless of error.
}
const sep = `\nEmitted 'error' event${ctorInfo} at:\n`;

const errStack = ArrayPrototypeSlice(
Expand Down Expand Up @@ -493,7 +495,9 @@ EventEmitter.prototype.emit = function emit(type, ...args) {
value: FunctionPrototypeBind(enhanceStackTrace, this, er, capture),
configurable: true
});
} catch {}
} catch {
// Continue regardless of error.
}

// Note: The comments on the `throw` lines are intentional, they show
// up in Node's output if this results in an unhandled exception.
Expand Down
4 changes: 3 additions & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1600,7 +1600,9 @@ function symlink(target, path, type_, callback_) {
// errors consistent between platforms if invalid path is
// provided.
absoluteTarget = pathModule.resolve(path, '..', target);
} catch { }
} catch {
// Continue regardless of error.
}
if (absoluteTarget !== undefined) {
stat(absoluteTarget, (err, stat) => {
const resolvedType = !err && stat.isDirectory() ? 'dir' : 'file';
Expand Down
4 changes: 3 additions & 1 deletion lib/internal/bootstrap/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ function patchProcessObject(expandArgv1) {
const path = require('path');
try {
process.argv[1] = path.resolve(process.argv[1]);
} catch {}
} catch {
// Continue regardless of error.
}
}

// TODO(joyeecheung): most of these should be deprecated and removed,
Expand Down
12 changes: 9 additions & 3 deletions lib/internal/error_serdes.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ function TryGetAllProperties(object, target = object) {
if (getter && key !== '__proto__') {
try {
descriptor.value = FunctionPrototypeCall(getter, target);
} catch {}
} catch {
// Continue regardless of error.
}
}
if ('value' in descriptor && typeof descriptor.value !== 'function') {
delete descriptor.get;
Expand Down Expand Up @@ -107,11 +109,15 @@ function serializeError(error) {
}
}
}
} catch {}
} catch {
// Continue regardless of error.
}
try {
const serialized = serialize(error);
return Buffer.concat([Buffer.from([kSerializedObject]), serialized]);
} catch {}
} catch {
// Continue regardless of error.
}
return Buffer.concat([Buffer.from([kInspectedError]),
Buffer.from(inspect(error), 'utf8')]);
}
Expand Down
8 changes: 6 additions & 2 deletions lib/internal/main/worker_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,18 @@ function workerOnGlobalUncaughtException(error, fromPromise) {
if (!handlerThrew) {
process.emit('exit', process.exitCode);
}
} catch {}
} catch {
// Continue regardless of error.
}
}

let serialized;
try {
const { serializeError } = require('internal/error_serdes');
serialized = serializeError(error);
} catch {}
} catch {
// Continue regardless of error.
}
debug(`[${threadId}] uncaught exception serialized = ${!!serialized}`);
if (serialized)
port.postMessage({
Expand Down
4 changes: 3 additions & 1 deletion lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,9 @@ Module._extensions['.js'] = function(module, filename) {
let parentSource;
try {
parentSource = fs.readFileSync(parentPath, 'utf8');
} catch {}
} catch {
// Continue regardless of error.
}
if (parentSource) {
const errLine = StringPrototypeSplit(
StringPrototypeSlice(err.stack, StringPrototypeIndexOf(
Expand Down
4 changes: 3 additions & 1 deletion lib/internal/modules/esm/module_job.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ class ModuleJob {
// care about CommonJS for the purposes of this error message.
({ format } =
await this.loader.load(childFileURL));
} catch {}
} catch {
// Continue regardless of error.
}

if (format === 'commonjs') {
const importStatement = splitStack[1];
Expand Down
4 changes: 3 additions & 1 deletion lib/internal/modules/esm/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,9 @@ function resolvePackageTargetString(
try {
new URL(target);
isURL = true;
} catch {}
} catch {
// Continue regardless of error.
}
if (!isURL) {
const exportTarget = pattern ?
RegExpPrototypeSymbolReplace(patternRegEx, target, () => subpath) :
Expand Down
8 changes: 6 additions & 2 deletions lib/internal/modules/esm/translators.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ translators.set('commonjs', async function commonjsStrategy(url, source,
let value;
try {
value = exports[exportName];
} catch {}
} catch {
// Continue regardless of error.
}
this.setExport(exportName, value);
}
this.setExport('default', exports);
Expand All @@ -205,7 +207,9 @@ function cjsPreparseModuleExports(filename) {
let source;
try {
source = readFileSync(filename, 'utf8');
} catch {}
} catch {
// Continue regardless of error.
}

let exports, reexports;
try {
Expand Down
4 changes: 3 additions & 1 deletion lib/internal/policy/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,9 @@ function canonicalizeSpecifier(specifier, base) {
return resolve(specifier, base).href;
}
return resolve(specifier).href;
} catch {}
} catch {
// Continue regardless of error.
}
return specifier;
}

Expand Down
4 changes: 3 additions & 1 deletion lib/internal/process/execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ function createOnGlobalUncaughtException() {
null,
er ?? {});
}
} catch {} // Ignore the exception. Diagnostic reporting is unavailable.
} catch {
// Ignore the exception. Diagnostic reporting is unavailable.
}
}

const type = fromPromise ? 'unhandledRejection' : 'uncaughtException';
Expand Down
4 changes: 3 additions & 1 deletion lib/internal/process/warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ function writeToFile(message) {
process.on('exit', () => {
try {
fs.closeSync(fd);
} catch {}
} catch {
// Continue regardless of error.
}
});
}
fs.appendFile(fd, `${message}\n`, (err) => {
Expand Down
4 changes: 3 additions & 1 deletion lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ function getUserOptions(ctx, isCrossContext) {
let stylized;
try {
stylized = `${ctx.stylize(value, flavour)}`;
} catch {}
} catch {
// Continue regardless of error.
}

if (typeof stylized !== 'string') return value;
// `stylized` is a string as it should be, which is safe to pass along.
Expand Down
6 changes: 5 additions & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ function REPLServer(prompt,
// to the parent of `process.cwd()`.
parentURL = pathToFileURL(path.join(process.cwd(), 'repl')).href;
} catch {
// Continue regardless of error.
}

// Remove all "await"s and attempt running the script
Expand Down Expand Up @@ -485,6 +486,7 @@ function REPLServer(prompt,
// to the parent of `process.cwd()`.
parentURL = pathToFileURL(path.join(process.cwd(), 'repl')).href;
} catch {
// Continue regardless of error.
}
while (true) {
try {
Expand Down Expand Up @@ -1236,7 +1238,9 @@ REPLServer.prototype.complete = function() {
function gracefulReaddir(...args) {
try {
return ReflectApply(fs.readdirSync, null, args);
} catch {}
} catch {
// Continue regardless of error.
}
}

function completeFSFunctions(line) {
Expand Down

0 comments on commit 7bf4fbc

Please sign in to comment.