Skip to content

Commit acd8768

Browse files
Trottdanielleadams
authored andcommitted
lib: add comments to empty catch statements
PR-URL: #41831 Backport-PR-URL: #42160 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 330c1bc commit acd8768

File tree

14 files changed

+59
-19
lines changed

14 files changed

+59
-19
lines changed

lib/events.js

Lines changed: 6 additions & 2 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ function patchProcessObject(expandArgv1) {
9797
const path = require('path');
9898
try {
9999
process.argv[1] = path.resolve(process.argv[1]);
100-
} catch {}
100+
} catch {
101+
// Continue regardless of error.
102+
}
101103
}
102104

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

lib/internal/error_serdes.js

Lines changed: 9 additions & 3 deletions
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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,18 @@ function workerOnGlobalUncaughtException(error, fromPromise) {
224224
if (!handlerThrew) {
225225
process.emit('exit', process.exitCode);
226226
}
227-
} catch {}
227+
} catch {
228+
// Continue regardless of error.
229+
}
228230
}
229231

230232
let serialized;
231233
try {
232234
const { serializeError } = require('internal/error_serdes');
233235
serialized = serializeError(error);
234-
} catch {}
236+
} catch {
237+
// Continue regardless of error.
238+
}
235239
debug(`[${threadId}] uncaught exception serialized = ${!!serialized}`);
236240
if (serialized)
237241
port.postMessage({

lib/internal/modules/cjs/loader.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,9 @@ Module._extensions['.js'] = function(module, filename) {
11341134
let parentSource;
11351135
try {
11361136
parentSource = fs.readFileSync(parentPath, 'utf8');
1137-
} catch {}
1137+
} catch {
1138+
// Continue regardless of error.
1139+
}
11381140
if (parentSource) {
11391141
const errLine = StringPrototypeSplit(
11401142
StringPrototypeSlice(err.stack, StringPrototypeIndexOf(

lib/internal/modules/esm/module_job.js

Lines changed: 3 additions & 1 deletion
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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,9 @@ function resolvePackageTargetString(
498498
try {
499499
new URL(target);
500500
isURL = true;
501-
} catch {}
501+
} catch {
502+
// Continue regardless of error.
503+
}
502504
if (!isURL) {
503505
const exportTarget = pattern ?
504506
RegExpPrototypeSymbolReplace(patternRegEx, target, () => subpath) :

lib/internal/modules/esm/translators.js

Lines changed: 6 additions & 2 deletions
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

Lines changed: 3 additions & 1 deletion
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

0 commit comments

Comments
 (0)