From 1558cf22f34236af13c39f09846b6beaf352281d Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 2 Feb 2022 21:57:11 -0800 Subject: [PATCH] lib: add comments to empty catch statements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/41831 Backport-PR-URL: https://github.com/nodejs/node/pull/42160 Refs: https://eslint.org/docs/rules/no-empty Reviewed-By: Colin Ihrig Reviewed-By: Tobias Nießen Reviewed-By: Antoine du Hamel --- lib/events.js | 8 ++++++-- lib/fs.js | 4 +++- lib/internal/bootstrap/pre_execution.js | 4 +++- lib/internal/error_serdes.js | 12 +++++++++--- lib/internal/main/worker_thread.js | 8 ++++++-- lib/internal/modules/cjs/loader.js | 4 +++- lib/internal/modules/esm/module_job.js | 4 +++- lib/internal/modules/esm/resolve.js | 4 +++- lib/internal/modules/esm/translators.js | 8 ++++++-- lib/internal/policy/manifest.js | 4 +++- lib/internal/process/execution.js | 4 +++- lib/internal/process/warning.js | 4 +++- lib/internal/util/inspect.js | 4 +++- lib/repl.js | 6 +++++- 14 files changed, 59 insertions(+), 19 deletions(-) diff --git a/lib/events.js b/lib/events.js index 3b992f39bf7990..e140c1a5f3d6bd 100644 --- a/lib/events.js +++ b/lib/events.js @@ -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( @@ -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. diff --git a/lib/fs.js b/lib/fs.js index c1cc7aecaa49e4..65c828ea110d2d 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -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'; diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js index 71b0afd4e67c99..f21ba048b48638 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -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, diff --git a/lib/internal/error_serdes.js b/lib/internal/error_serdes.js index 6a2081b8e2d4ff..c364820f60b1aa 100644 --- a/lib/internal/error_serdes.js +++ b/lib/internal/error_serdes.js @@ -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; @@ -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')]); } diff --git a/lib/internal/main/worker_thread.js b/lib/internal/main/worker_thread.js index 71a07a63a3636a..65827ecd593ffb 100644 --- a/lib/internal/main/worker_thread.js +++ b/lib/internal/main/worker_thread.js @@ -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({ diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 5c2de2d9c57ffd..cfe2982bf22c24 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -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( diff --git a/lib/internal/modules/esm/module_job.js b/lib/internal/modules/esm/module_job.js index 018d598796f153..fd1c6166330e76 100644 --- a/lib/internal/modules/esm/module_job.js +++ b/lib/internal/modules/esm/module_job.js @@ -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]; diff --git a/lib/internal/modules/esm/resolve.js b/lib/internal/modules/esm/resolve.js index 688c0410a3e063..a4be89cc949b76 100644 --- a/lib/internal/modules/esm/resolve.js +++ b/lib/internal/modules/esm/resolve.js @@ -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) : diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js index 297ac95e662670..da95703faad9fd 100644 --- a/lib/internal/modules/esm/translators.js +++ b/lib/internal/modules/esm/translators.js @@ -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); @@ -205,7 +207,9 @@ function cjsPreparseModuleExports(filename) { let source; try { source = readFileSync(filename, 'utf8'); - } catch {} + } catch { + // Continue regardless of error. + } let exports, reexports; try { diff --git a/lib/internal/policy/manifest.js b/lib/internal/policy/manifest.js index 61ee55d3a45637..a3f6d347d47025 100644 --- a/lib/internal/policy/manifest.js +++ b/lib/internal/policy/manifest.js @@ -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; } diff --git a/lib/internal/process/execution.js b/lib/internal/process/execution.js index 1311349951c5b9..4a8e51f694f7e6 100644 --- a/lib/internal/process/execution.js +++ b/lib/internal/process/execution.js @@ -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'; diff --git a/lib/internal/process/warning.js b/lib/internal/process/warning.js index 90c6076dc54965..9778990630dcaa 100644 --- a/lib/internal/process/warning.js +++ b/lib/internal/process/warning.js @@ -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) => { diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index ca3227dea43c99..d78a4e97d218a6 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -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. diff --git a/lib/repl.js b/lib/repl.js index c576f5b7f3094d..8e31ec43add7cc 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -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 @@ -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 { @@ -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) {