Skip to content

Commit 4834be3

Browse files
Trottruyadorno
authored andcommittedFeb 8, 2022
lib: add comments to empty catch statements
PR-URL: #41831 Refs: https://eslint.org/docs/rules/no-empty Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 8a42a20 commit 4834be3

File tree

14 files changed

+59
-19
lines changed

14 files changed

+59
-19
lines changed
 

‎lib/events.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,9 @@ function enhanceStackTrace(err, own) {
445445
const { name } = this.constructor;
446446
if (name !== 'EventEmitter')
447447
ctorInfo = ` on ${name} instance`;
448-
} catch {}
448+
} catch {
449+
// Continue regardless of error.
450+
}
449451
const sep = `\nEmitted 'error' event${ctorInfo} at:\n`;
450452

451453
const errStack = ArrayPrototypeSlice(
@@ -493,7 +495,9 @@ EventEmitter.prototype.emit = function emit(type, ...args) {
493495
value: FunctionPrototypeBind(enhanceStackTrace, this, er, capture),
494496
configurable: true
495497
});
496-
} catch {}
498+
} catch {
499+
// Continue regardless of error.
500+
}
497501

498502
// Note: The comments on the `throw` lines are intentional, they show
499503
// up in Node's output if this results in an unhandled exception.

‎lib/fs.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,9 @@ function symlink(target, path, type_, callback_) {
16001600
// errors consistent between platforms if invalid path is
16011601
// provided.
16021602
absoluteTarget = pathModule.resolve(path, '..', target);
1603-
} catch { }
1603+
} catch {
1604+
// Continue regardless of error.
1605+
}
16041606
if (absoluteTarget !== undefined) {
16051607
stat(absoluteTarget, (err, stat) => {
16061608
const resolvedType = !err && stat.isDirectory() ? 'dir' : 'file';

‎lib/internal/bootstrap/pre_execution.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ function patchProcessObject(expandArgv1) {
101101
const path = require('path');
102102
try {
103103
process.argv[1] = path.resolve(process.argv[1]);
104-
} catch {}
104+
} catch {
105+
// Continue regardless of error.
106+
}
105107
}
106108

107109
// TODO(joyeecheung): most of these should be deprecated and removed,

‎lib/internal/error_serdes.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ function TryGetAllProperties(object, target = object) {
4848
if (getter && key !== '__proto__') {
4949
try {
5050
descriptor.value = FunctionPrototypeCall(getter, target);
51-
} catch {}
51+
} catch {
52+
// Continue regardless of error.
53+
}
5254
}
5355
if ('value' in descriptor && typeof descriptor.value !== 'function') {
5456
delete descriptor.get;
@@ -107,11 +109,15 @@ function serializeError(error) {
107109
}
108110
}
109111
}
110-
} catch {}
112+
} catch {
113+
// Continue regardless of error.
114+
}
111115
try {
112116
const serialized = serialize(error);
113117
return Buffer.concat([Buffer.from([kSerializedObject]), serialized]);
114-
} catch {}
118+
} catch {
119+
// Continue regardless of error.
120+
}
115121
return Buffer.concat([Buffer.from([kInspectedError]),
116122
Buffer.from(inspect(error), 'utf8')]);
117123
}

‎lib/internal/main/worker_thread.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,18 @@ function workerOnGlobalUncaughtException(error, fromPromise) {
226226
if (!handlerThrew) {
227227
process.emit('exit', process.exitCode);
228228
}
229-
} catch {}
229+
} catch {
230+
// Continue regardless of error.
231+
}
230232
}
231233

232234
let serialized;
233235
try {
234236
const { serializeError } = require('internal/error_serdes');
235237
serialized = serializeError(error);
236-
} catch {}
238+
} catch {
239+
// Continue regardless of error.
240+
}
237241
debug(`[${threadId}] uncaught exception serialized = ${!!serialized}`);
238242
if (serialized)
239243
port.postMessage({

‎lib/internal/modules/cjs/loader.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,9 @@ Module._extensions['.js'] = function(module, filename) {
11281128
let parentSource;
11291129
try {
11301130
parentSource = fs.readFileSync(parentPath, 'utf8');
1131-
} catch {}
1131+
} catch {
1132+
// Continue regardless of error.
1133+
}
11321134
if (parentSource) {
11331135
const errLine = StringPrototypeSplit(
11341136
StringPrototypeSlice(err.stack, StringPrototypeIndexOf(

‎lib/internal/modules/esm/module_job.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ class ModuleJob {
154154
// care about CommonJS for the purposes of this error message.
155155
({ format } =
156156
await this.loader.load(childFileURL));
157-
} catch {}
157+
} catch {
158+
// Continue regardless of error.
159+
}
158160

159161
if (format === 'commonjs') {
160162
const importStatement = splitStack[1];

‎lib/internal/modules/esm/resolve.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,9 @@ function resolvePackageTargetString(
474474
try {
475475
new URL(target);
476476
isURL = true;
477-
} catch {}
477+
} catch {
478+
// Continue regardless of error.
479+
}
478480
if (!isURL) {
479481
const exportTarget = pattern ?
480482
RegExpPrototypeSymbolReplace(patternRegEx, target, () => subpath) :

‎lib/internal/modules/esm/translators.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ translators.set('commonjs', async function commonjsStrategy(url, source,
180180
let value;
181181
try {
182182
value = exports[exportName];
183-
} catch {}
183+
} catch {
184+
// Continue regardless of error.
185+
}
184186
this.setExport(exportName, value);
185187
}
186188
this.setExport('default', exports);
@@ -205,7 +207,9 @@ function cjsPreparseModuleExports(filename) {
205207
let source;
206208
try {
207209
source = readFileSync(filename, 'utf8');
208-
} catch {}
210+
} catch {
211+
// Continue regardless of error.
212+
}
209213

210214
let exports, reexports;
211215
try {

‎lib/internal/policy/manifest.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,9 @@ function canonicalizeSpecifier(specifier, base) {
639639
return resolve(specifier, base).href;
640640
}
641641
return resolve(specifier).href;
642-
} catch {}
642+
} catch {
643+
// Continue regardless of error.
644+
}
643645
return specifier;
644646
}
645647

‎lib/internal/process/execution.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ function createOnGlobalUncaughtException() {
155155
null,
156156
er ?? {});
157157
}
158-
} catch {} // Ignore the exception. Diagnostic reporting is unavailable.
158+
} catch {
159+
// Ignore the exception. Diagnostic reporting is unavailable.
160+
}
159161
}
160162

161163
const type = fromPromise ? 'unhandledRejection' : 'uncaughtException';

‎lib/internal/process/warning.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ function writeToFile(message) {
6161
process.on('exit', () => {
6262
try {
6363
fs.closeSync(fd);
64-
} catch {}
64+
} catch {
65+
// Continue regardless of error.
66+
}
6567
});
6668
}
6769
fs.appendFile(fd, `${message}\n`, (err) => {

‎lib/internal/util/inspect.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ function getUserOptions(ctx, isCrossContext) {
268268
let stylized;
269269
try {
270270
stylized = `${ctx.stylize(value, flavour)}`;
271-
} catch {}
271+
} catch {
272+
// Continue regardless of error.
273+
}
272274

273275
if (typeof stylized !== 'string') return value;
274276
// `stylized` is a string as it should be, which is safe to pass along.

‎lib/repl.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ function REPLServer(prompt,
445445
// to the parent of `process.cwd()`.
446446
parentURL = pathToFileURL(path.join(process.cwd(), 'repl')).href;
447447
} catch {
448+
// Continue regardless of error.
448449
}
449450

450451
// Remove all "await"s and attempt running the script
@@ -485,6 +486,7 @@ function REPLServer(prompt,
485486
// to the parent of `process.cwd()`.
486487
parentURL = pathToFileURL(path.join(process.cwd(), 'repl')).href;
487488
} catch {
489+
// Continue regardless of error.
488490
}
489491
while (true) {
490492
try {
@@ -1236,7 +1238,9 @@ REPLServer.prototype.complete = function() {
12361238
function gracefulReaddir(...args) {
12371239
try {
12381240
return ReflectApply(fs.readdirSync, null, args);
1239-
} catch {}
1241+
} catch {
1242+
// Continue regardless of error.
1243+
}
12401244
}
12411245

12421246
function completeFSFunctions(line) {

0 commit comments

Comments
 (0)
Please sign in to comment.