From c9bae5da8ef280e310d4c1d03ee94a169c704357 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Thu, 27 Jul 2023 16:53:45 +0200 Subject: [PATCH] refactor: use optional catch binding (#39232) --- spec/api-app-spec.ts | 2 +- spec/api-auto-updater-spec.ts | 4 ++-- spec/api-crash-reporter-spec.ts | 4 ++-- spec/api-debugger-spec.ts | 2 +- spec/api-net-log-spec.ts | 2 +- spec/api-process-spec.ts | 4 ++-- spec/api-protocol-spec.ts | 6 +++--- spec/api-web-contents-spec.ts | 2 +- spec/fixtures/api/default-menu/main.js | 4 ++-- spec/fixtures/module/echo-renamed.js | 2 +- spec/webview-spec.ts | 2 +- 11 files changed, 17 insertions(+), 17 deletions(-) diff --git a/spec/api-app-spec.ts b/spec/api-app-spec.ts index 79c3388cb1fe..87b6e616484f 100644 --- a/spec/api-app-spec.ts +++ b/spec/api-app-spec.ts @@ -345,7 +345,7 @@ describe('app module', () => { expectedAdditionalData: undefined }); assert(false); - } catch (e) { + } catch { // This is expected. } }); diff --git a/spec/api-auto-updater-spec.ts b/spec/api-auto-updater-spec.ts index ec0da4b9bd45..e558dbf51755 100644 --- a/spec/api-auto-updater-spec.ts +++ b/spec/api-auto-updater-spec.ts @@ -32,7 +32,7 @@ ifdescribe(!process.mas)('autoUpdater module', function () { const url = 'http://electronjs.org'; try { (autoUpdater.setFeedURL as any)(url, { header: 'val' }); - } catch (err) { /* ignore */ } + } catch { /* ignore */ } expect(autoUpdater.getFeedURL()).to.equal(url); }); @@ -44,7 +44,7 @@ ifdescribe(!process.mas)('autoUpdater module', function () { const url = 'http://mymagicurl.local'; try { autoUpdater.setFeedURL({ url }); - } catch (err) { /* ignore */ } + } catch { /* ignore */ } expect(autoUpdater.getFeedURL()).to.equal(url); }); diff --git a/spec/api-crash-reporter-spec.ts b/spec/api-crash-reporter-spec.ts index e7232573dfde..bc7afe2cddf8 100644 --- a/spec/api-crash-reporter-spec.ts +++ b/spec/api-crash-reporter-spec.ts @@ -116,7 +116,7 @@ function waitForNewFileInDir (dir: string): Promise { function readdirIfPresent (dir: string): string[] { try { return fs.readdirSync(dir); - } catch (e) { + } catch { return []; } } @@ -402,7 +402,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_ try { fs.rmdirSync(dir, { recursive: true }); fs.mkdirSync(dir); - } catch (e) { /* ignore */ } + } catch { /* ignore */ } // 1. start the crash reporter. await remotely((port: number) => { diff --git a/spec/api-debugger-spec.ts b/spec/api-debugger-spec.ts index 311b7ec6c673..057f39e41846 100644 --- a/spec/api-debugger-spec.ts +++ b/spec/api-debugger-spec.ts @@ -32,7 +32,7 @@ describe('debugger module', () => { it('fails when protocol version is not supported', done => { try { w.webContents.debugger.attach('2.0'); - } catch (err) { + } catch { expect(w.webContents.debugger.isAttached()).to.be.false(); done(); } diff --git a/spec/api-net-log-spec.ts b/spec/api-net-log-spec.ts index eb5957e82587..fc570f229759 100644 --- a/spec/api-net-log-spec.ts +++ b/spec/api-net-log-spec.ts @@ -55,7 +55,7 @@ describe('netLog module', () => { if (fs.existsSync(dumpFileDynamic)) { fs.unlinkSync(dumpFileDynamic); } - } catch (e) { + } catch { // Ignore error } expect(testNetLog().currentlyLogging).to.be.false('currently logging'); diff --git a/spec/api-process-spec.ts b/spec/api-process-spec.ts index a5d1326a661b..7ae874c7fea2 100644 --- a/spec/api-process-spec.ts +++ b/spec/api-process-spec.ts @@ -99,7 +99,7 @@ describe('process module', () => { defer(() => { try { fs.unlinkSync(filePath); - } catch (e) { + } catch { // ignore error } }); @@ -211,7 +211,7 @@ describe('process module', () => { defer(() => { try { fs.unlinkSync(filePath); - } catch (e) { + } catch { // ignore error } }); diff --git a/spec/api-protocol-spec.ts b/spec/api-protocol-spec.ts index 90b07b707422..72dfe18fe89d 100644 --- a/spec/api-protocol-spec.ts +++ b/spec/api-protocol-spec.ts @@ -104,7 +104,7 @@ describe('protocol module', () => { try { callback(text); callback(''); - } catch (error) { + } catch { // Ignore error } }); @@ -557,7 +557,7 @@ describe('protocol module', () => { try { callback(text); callback(''); - } catch (error) { + } catch { // Ignore error } }); @@ -1106,7 +1106,7 @@ describe('protocol module', () => { // In case of failure, make sure we unhandle. But we should succeed // :) protocol.unhandle('test-scheme'); - } catch (_ignored) { /* ignore */ } + } catch { /* ignore */ } }); const resp1 = await net.fetch('test-scheme://foo'); expect(resp1.status).to.equal(200); diff --git a/spec/api-web-contents-spec.ts b/spec/api-web-contents-spec.ts index 7445111b632e..aeb2a1134988 100644 --- a/spec/api-web-contents-spec.ts +++ b/spec/api-web-contents-spec.ts @@ -1786,7 +1786,7 @@ describe('webContents module', () => { const cleanup = () => { try { fs.unlinkSync(filePath); - } catch (e) { + } catch { // ignore error } }; diff --git a/spec/fixtures/api/default-menu/main.js b/spec/fixtures/api/default-menu/main.js index 16e84badc913..28cad7a2936b 100644 --- a/spec/fixtures/api/default-menu/main.js +++ b/spec/fixtures/api/default-menu/main.js @@ -22,11 +22,11 @@ try { setImmediate(() => { try { output(Menu.getApplicationMenu() === expectedMenu); - } catch (error) { + } catch { output(null); } }); }); -} catch (error) { +} catch { output(null); } diff --git a/spec/fixtures/module/echo-renamed.js b/spec/fixtures/module/echo-renamed.js index 6dfa05f914a3..d81f922c21f6 100644 --- a/spec/fixtures/module/echo-renamed.js +++ b/spec/fixtures/module/echo-renamed.js @@ -1,7 +1,7 @@ let echo; try { echo = require('@electron-ci/echo'); -} catch (e) { +} catch { process.exit(1); } process.exit(echo(0)); diff --git a/spec/webview-spec.ts b/spec/webview-spec.ts index 51c2ab952ba6..06ad8c527f1c 100644 --- a/spec/webview-spec.ts +++ b/spec/webview-spec.ts @@ -2032,7 +2032,7 @@ describe(' tag', function () { // Values can be 0,2,3,4, or 6. We want 6, which is RGB + Alpha expect(imgBuffer[25]).to.equal(6); return; - } catch (e) { + } catch { /* drop the error */ } }