From 4e244937c93b08abc002094bf31c31c0d223b396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Fri, 3 Mar 2023 18:18:49 +0100 Subject: [PATCH] refactor: `catch` doesn't need to have a param (no-changelog) (#5614) --- packages/cli/src/CommunityNodes/helpers.ts | 4 ++-- packages/cli/src/CurlConverterHelper.ts | 2 +- packages/cli/src/LoadNodesAndCredentials.ts | 6 ++--- .../credentials/credentials.middleware.ts | 2 +- packages/cli/src/api/nodes.api.ts | 2 +- .../src/controllers/translation.controller.ts | 2 +- .../sqlite/1659888469333-AddJsonKeyPinData.ts | 2 +- .../MessageEventBusDestinationWebhook.ee.ts | 18 +++++++-------- packages/core/src/DirectoryLoader.ts | 2 +- .../CodeNodeEditor/CodeNodeEditor.vue | 2 +- .../components/CodeNodeEditor/completer.ts | 2 +- .../completions/jsonField.completions.ts | 6 ++--- .../src/components/CodeNodeEditor/linter.ts | 4 ++-- .../editor-ui/src/components/NodeSettings.vue | 2 +- .../completions/bracketAccess.completions.ts | 2 +- .../completions/datatype.completions.ts | 4 ++-- .../HttpRequest/V1/HttpRequestV1.node.ts | 12 +++++----- .../HttpRequest/V2/HttpRequestV2.node.ts | 16 +++++++------- .../HttpRequest/V3/HttpRequestV3.node.ts | 22 +++++++++---------- packages/workflow/src/TelemetryHelpers.ts | 6 ++--- 20 files changed, 59 insertions(+), 59 deletions(-) diff --git a/packages/cli/src/CommunityNodes/helpers.ts b/packages/cli/src/CommunityNodes/helpers.ts index cd18a967b4..295f6a1072 100644 --- a/packages/cli/src/CommunityNodes/helpers.ts +++ b/packages/cli/src/CommunityNodes/helpers.ts @@ -88,7 +88,7 @@ export const executeCommand = async ( try { await fsAccess(downloadFolder); - } catch (_) { + } catch { await fsMkdir(downloadFolder); // Also init the folder since some versions // of npm complain if the folder is empty @@ -154,7 +154,7 @@ export function matchMissingPackages( return parsedPackageData.packageName; // eslint-disable-next-line no-empty - } catch (_) {} + } catch {} return undefined; }); diff --git a/packages/cli/src/CurlConverterHelper.ts b/packages/cli/src/CurlConverterHelper.ts index cee25c0d73..d59b3f5375 100644 --- a/packages/cli/src/CurlConverterHelper.ts +++ b/packages/cli/src/CurlConverterHelper.ts @@ -125,7 +125,7 @@ const isJsonRequest = (curlJson: CurlJson): boolean => { try { JSON.parse(bodyKey); return true; - } catch (_) { + } catch { return false; } } diff --git a/packages/cli/src/LoadNodesAndCredentials.ts b/packages/cli/src/LoadNodesAndCredentials.ts index 4003f6ee58..f25cef5f3b 100644 --- a/packages/cli/src/LoadNodesAndCredentials.ts +++ b/packages/cli/src/LoadNodesAndCredentials.ts @@ -217,7 +217,7 @@ export class LoadNodesAndCredentials implements INodesAndCredentials { const removeCommand = `npm remove ${packageName}`; try { await executeCommand(removeCommand); - } catch (_) {} + } catch {} throw new Error(RESPONSE_ERROR_MESSAGES.PACKAGE_DOES_NOT_CONTAIN_NODES); } @@ -284,7 +284,7 @@ export class LoadNodesAndCredentials implements INodesAndCredentials { const removeCommand = `npm remove ${packageName}`; try { await executeCommand(removeCommand); - } catch (_) {} + } catch {} throw new Error(RESPONSE_ERROR_MESSAGES.PACKAGE_DOES_NOT_CONTAIN_NODES); } } @@ -418,7 +418,7 @@ export class LoadNodesAndCredentials implements INodesAndCredentials { await fsAccess(checkPath); // Folder exists, so use it. return path.dirname(checkPath); - } catch (_) {} // Folder does not exist so get next one + } catch {} // Folder does not exist so get next one } throw new Error('Could not find "node_modules" folder!'); } diff --git a/packages/cli/src/PublicApi/v1/handlers/credentials/credentials.middleware.ts b/packages/cli/src/PublicApi/v1/handlers/credentials/credentials.middleware.ts index 097a50e5e6..d314151f95 100644 --- a/packages/cli/src/PublicApi/v1/handlers/credentials/credentials.middleware.ts +++ b/packages/cli/src/PublicApi/v1/handlers/credentials/credentials.middleware.ts @@ -16,7 +16,7 @@ export const validCredentialType = ( ): express.Response | void => { try { Container.get(CredentialTypes).getByName(req.body.type); - } catch (_) { + } catch { return res.status(400).json({ message: 'req.body.type is not a known type' }); } diff --git a/packages/cli/src/api/nodes.api.ts b/packages/cli/src/api/nodes.api.ts index 2b2ade1784..70264cdab5 100644 --- a/packages/cli/src/api/nodes.api.ts +++ b/packages/cli/src/api/nodes.api.ts @@ -202,7 +202,7 @@ nodesController.get( if (missingPackages) { hydratedPackages = matchMissingPackages(hydratedPackages, missingPackages); } - } catch (_) { + } catch { // Do nothing if setting is missing } diff --git a/packages/cli/src/controllers/translation.controller.ts b/packages/cli/src/controllers/translation.controller.ts index 8d24f9e113..8240a376a7 100644 --- a/packages/cli/src/controllers/translation.controller.ts +++ b/packages/cli/src/controllers/translation.controller.ts @@ -44,7 +44,7 @@ export class TranslationController { async getNodeTranslationHeaders() { try { await access(`${NODE_HEADERS_PATH}.js`); - } catch (_) { + } catch { return; // no headers available } diff --git a/packages/cli/src/databases/migrations/sqlite/1659888469333-AddJsonKeyPinData.ts b/packages/cli/src/databases/migrations/sqlite/1659888469333-AddJsonKeyPinData.ts index 11eea4686e..f2ce0f0bad 100644 --- a/packages/cli/src/databases/migrations/sqlite/1659888469333-AddJsonKeyPinData.ts +++ b/packages/cli/src/databases/migrations/sqlite/1659888469333-AddJsonKeyPinData.ts @@ -69,7 +69,7 @@ function makeUpdateParams(fetchedWorkflows: PinData.FetchedWorkflow[]) { if (typeof rawPinData === 'string') { try { pinDataPerWorkflow = JSON.parse(rawPinData); - } catch (_) { + } catch { pinDataPerWorkflow = {}; } } else { diff --git a/packages/cli/src/eventbus/MessageEventBusDestination/MessageEventBusDestinationWebhook.ee.ts b/packages/cli/src/eventbus/MessageEventBusDestination/MessageEventBusDestinationWebhook.ee.ts index 95dcd340d6..fb3f47db2f 100644 --- a/packages/cli/src/eventbus/MessageEventBusDestination/MessageEventBusDestinationWebhook.ee.ts +++ b/packages/cli/src/eventbus/MessageEventBusDestination/MessageEventBusDestinationWebhook.ee.ts @@ -132,7 +132,7 @@ export class MessageEventBusDestinationWebhook let encryptionKey: string | undefined; try { encryptionKey = await UserSettings.getEncryptionKey(); - } catch (_) {} + } catch {} if (encryptionKey) { this.credentialsHelper = new CredentialsHelper(encryptionKey); } @@ -189,7 +189,7 @@ export class MessageEventBusDestinationWebhook // query is specified using JSON try { JSON.parse(this.jsonQuery); - } catch (_) { + } catch { console.log('JSON parameter need to be an valid JSON'); } this.axiosRequestOptions.params = jsonParse(this.jsonQuery); @@ -207,7 +207,7 @@ export class MessageEventBusDestinationWebhook // body is specified using JSON try { JSON.parse(this.jsonHeaders); - } catch (_) { + } catch { console.log('JSON parameter need to be an valid JSON'); } this.axiosRequestOptions.headers = jsonParse(this.jsonHeaders); @@ -302,27 +302,27 @@ export class MessageEventBusDestinationWebhook if (this.genericAuthType === 'httpBasicAuth') { try { httpBasicAuth = await this.matchDecryptedCredentialType('httpBasicAuth'); - } catch (_) {} + } catch {} } else if (this.genericAuthType === 'httpDigestAuth') { try { httpDigestAuth = await this.matchDecryptedCredentialType('httpDigestAuth'); - } catch (_) {} + } catch {} } else if (this.genericAuthType === 'httpHeaderAuth') { try { httpHeaderAuth = await this.matchDecryptedCredentialType('httpHeaderAuth'); - } catch (_) {} + } catch {} } else if (this.genericAuthType === 'httpQueryAuth') { try { httpQueryAuth = await this.matchDecryptedCredentialType('httpQueryAuth'); - } catch (_) {} + } catch {} } else if (this.genericAuthType === 'oAuth1Api') { try { oAuth1Api = await this.matchDecryptedCredentialType('oAuth1Api'); - } catch (_) {} + } catch {} } else if (this.genericAuthType === 'oAuth2Api') { try { oAuth2Api = await this.matchDecryptedCredentialType('oAuth2Api'); - } catch (_) {} + } catch {} } } diff --git a/packages/core/src/DirectoryLoader.ts b/packages/core/src/DirectoryLoader.ts index 5709efa819..296214a029 100644 --- a/packages/core/src/DirectoryLoader.ts +++ b/packages/core/src/DirectoryLoader.ts @@ -233,7 +233,7 @@ export abstract class DirectoryLoader { } node.description.codex = codex; - } catch (_) { + } catch { Logger.debug(`No codex available for: ${filePath.split('/').pop() ?? ''}`); if (isCustom) { diff --git a/packages/editor-ui/src/components/CodeNodeEditor/CodeNodeEditor.vue b/packages/editor-ui/src/components/CodeNodeEditor/CodeNodeEditor.vue index 80b4dd392d..d01804660d 100644 --- a/packages/editor-ui/src/components/CodeNodeEditor/CodeNodeEditor.vue +++ b/packages/editor-ui/src/components/CodeNodeEditor/CodeNodeEditor.vue @@ -129,7 +129,7 @@ export default mixins(linterExtension, completerExtension, workflowHelpers).exte context, inserted_text: insertedText, }); - } catch (_) {} + } catch {} }, }, destroyed() { diff --git a/packages/editor-ui/src/components/CodeNodeEditor/completer.ts b/packages/editor-ui/src/components/CodeNodeEditor/completer.ts index 0d4f03c9c7..d37e979499 100644 --- a/packages/editor-ui/src/components/CodeNodeEditor/completer.ts +++ b/packages/editor-ui/src/components/CodeNodeEditor/completer.ts @@ -84,7 +84,7 @@ export const completerExtension = mixins( try { variablesToValues = this.variablesToValues(); - } catch (_) { + } catch { return null; } diff --git a/packages/editor-ui/src/components/CodeNodeEditor/completions/jsonField.completions.ts b/packages/editor-ui/src/components/CodeNodeEditor/completions/jsonField.completions.ts index 416950a80f..5d5d3f09d3 100644 --- a/packages/editor-ui/src/components/CodeNodeEditor/completions/jsonField.completions.ts +++ b/packages/editor-ui/src/components/CodeNodeEditor/completions/jsonField.completions.ts @@ -220,7 +220,7 @@ export const jsonFieldCompletions = (Vue as CodeNodeEditorMixin).extend({ return input.main[0][0].node; } - } catch (_) { + } catch { return null; } }, @@ -291,7 +291,7 @@ export const jsonFieldCompletions = (Vue as CodeNodeEditorMixin).extend({ } return nodePinData[itemIndex].json; - } catch (_) {} + } catch {} } const runData: IRunData | null = this.workflowsStore.getWorkflowRunData; @@ -309,7 +309,7 @@ export const jsonFieldCompletions = (Vue as CodeNodeEditorMixin).extend({ } return nodeRunData[0].data!.main[0]![itemIndex].json; - } catch (_) { + } catch { return null; } }, diff --git a/packages/editor-ui/src/components/CodeNodeEditor/linter.ts b/packages/editor-ui/src/components/CodeNodeEditor/linter.ts index 80ad93af1f..96fe8d397b 100644 --- a/packages/editor-ui/src/components/CodeNodeEditor/linter.ts +++ b/packages/editor-ui/src/components/CodeNodeEditor/linter.ts @@ -35,7 +35,7 @@ export const linterExtension = (Vue as CodeNodeEditorMixin).extend({ // optional chaining operators currently unsupported by esprima-next if (['?.', ']?'].some((operator) => lineAtError.includes(operator))) return []; - } catch (_) { + } catch { return []; } @@ -50,7 +50,7 @@ export const linterExtension = (Vue as CodeNodeEditorMixin).extend({ message: this.$locale.baseText('codeNodeEditor.linter.bothModes.syntaxError'), }, ]; - } catch (_) { + } catch { /** * For invalid (e.g. half-written) n8n syntax, esprima errors with an off-by-one line number for the final line. In future, we should add full linting for n8n syntax before parsing JS. */ diff --git a/packages/editor-ui/src/components/NodeSettings.vue b/packages/editor-ui/src/components/NodeSettings.vue index 2bfd979c43..51462d075a 100644 --- a/packages/editor-ui/src/components/NodeSettings.vue +++ b/packages/editor-ui/src/components/NodeSettings.vue @@ -484,7 +484,7 @@ export default mixins(externalHooks, nodeHelpers).extend({ }); this.uiStore.setHttpNodeParameters({ name: IMPORT_CURL_MODAL_KEY, parameters: '' }); - } catch (_) {} + } catch {} } }, }, diff --git a/packages/editor-ui/src/plugins/codemirror/completions/bracketAccess.completions.ts b/packages/editor-ui/src/plugins/codemirror/completions/bracketAccess.completions.ts index 4c3254b4b6..26f579c760 100644 --- a/packages/editor-ui/src/plugins/codemirror/completions/bracketAccess.completions.ts +++ b/packages/editor-ui/src/plugins/codemirror/completions/bracketAccess.completions.ts @@ -32,7 +32,7 @@ export function bracketAccessCompletions(context: CompletionContext): Completion try { resolved = resolveParameter(`={{ ${base} }}`); - } catch (_) { + } catch { return null; } diff --git a/packages/editor-ui/src/plugins/codemirror/completions/datatype.completions.ts b/packages/editor-ui/src/plugins/codemirror/completions/datatype.completions.ts index e64158059e..1362354167 100644 --- a/packages/editor-ui/src/plugins/codemirror/completions/datatype.completions.ts +++ b/packages/editor-ui/src/plugins/codemirror/completions/datatype.completions.ts @@ -44,7 +44,7 @@ export function datatypeCompletions(context: CompletionContext): CompletionResul try { resolved = resolveParameter(`={{ ${base} }}`); - } catch (_) { + } catch { return null; } @@ -52,7 +52,7 @@ export function datatypeCompletions(context: CompletionContext): CompletionResul try { options = datatypeOptions(resolved, base).map(stripExcessParens(context)); - } catch (_) { + } catch { return null; } } diff --git a/packages/nodes-base/nodes/HttpRequest/V1/HttpRequestV1.node.ts b/packages/nodes-base/nodes/HttpRequest/V1/HttpRequestV1.node.ts index 0dbad1a8e5..17169ca230 100644 --- a/packages/nodes-base/nodes/HttpRequest/V1/HttpRequestV1.node.ts +++ b/packages/nodes-base/nodes/HttpRequest/V1/HttpRequestV1.node.ts @@ -611,22 +611,22 @@ export class HttpRequestV1 implements INodeType { try { httpBasicAuth = await this.getCredentials('httpBasicAuth'); - } catch (_) {} + } catch {} try { httpDigestAuth = await this.getCredentials('httpDigestAuth'); - } catch (_) {} + } catch {} try { httpHeaderAuth = await this.getCredentials('httpHeaderAuth'); - } catch (_) {} + } catch {} try { httpQueryAuth = await this.getCredentials('httpQueryAuth'); - } catch (_) {} + } catch {} try { oAuth1Api = await this.getCredentials('oAuth1Api'); - } catch (_) {} + } catch {} try { oAuth2Api = await this.getCredentials('oAuth2Api'); - } catch (_) {} + } catch {} let requestOptions: OptionsWithUri; let setUiParameter: IDataObject; diff --git a/packages/nodes-base/nodes/HttpRequest/V2/HttpRequestV2.node.ts b/packages/nodes-base/nodes/HttpRequest/V2/HttpRequestV2.node.ts index 89fabccbaf..57462c4b07 100644 --- a/packages/nodes-base/nodes/HttpRequest/V2/HttpRequestV2.node.ts +++ b/packages/nodes-base/nodes/HttpRequest/V2/HttpRequestV2.node.ts @@ -621,7 +621,7 @@ export class HttpRequestV2 implements INodeType { | 'predefinedCredentialType' | 'genericCredentialType' | 'none'; - } catch (_) {} + } catch {} let httpBasicAuth; let httpDigestAuth; @@ -637,32 +637,32 @@ export class HttpRequestV2 implements INodeType { if (genericAuthType === 'httpBasicAuth') { try { httpBasicAuth = await this.getCredentials('httpBasicAuth'); - } catch (_) {} + } catch {} } else if (genericAuthType === 'httpDigestAuth') { try { httpDigestAuth = await this.getCredentials('httpDigestAuth'); - } catch (_) {} + } catch {} } else if (genericAuthType === 'httpHeaderAuth') { try { httpHeaderAuth = await this.getCredentials('httpHeaderAuth'); - } catch (_) {} + } catch {} } else if (genericAuthType === 'httpQueryAuth') { try { httpQueryAuth = await this.getCredentials('httpQueryAuth'); - } catch (_) {} + } catch {} } else if (genericAuthType === 'oAuth1Api') { try { oAuth1Api = await this.getCredentials('oAuth1Api'); - } catch (_) {} + } catch {} } else if (genericAuthType === 'oAuth2Api') { try { oAuth2Api = await this.getCredentials('oAuth2Api'); - } catch (_) {} + } catch {} } } else if (authentication === 'predefinedCredentialType') { try { nodeCredentialType = this.getNodeParameter('nodeCredentialType', 0) as string; - } catch (_) {} + } catch {} } let requestOptions: OptionsWithUri; diff --git a/packages/nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts b/packages/nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts index 45570b6df2..56cc06f8f1 100644 --- a/packages/nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts +++ b/packages/nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts @@ -888,7 +888,7 @@ export class HttpRequestV3 implements INodeType { | 'predefinedCredentialType' | 'genericCredentialType' | 'none'; - } catch (_) {} + } catch {} let httpBasicAuth; let httpDigestAuth; @@ -904,32 +904,32 @@ export class HttpRequestV3 implements INodeType { if (genericAuthType === 'httpBasicAuth') { try { httpBasicAuth = await this.getCredentials('httpBasicAuth'); - } catch (_) {} + } catch {} } else if (genericAuthType === 'httpDigestAuth') { try { httpDigestAuth = await this.getCredentials('httpDigestAuth'); - } catch (_) {} + } catch {} } else if (genericAuthType === 'httpHeaderAuth') { try { httpHeaderAuth = await this.getCredentials('httpHeaderAuth'); - } catch (_) {} + } catch {} } else if (genericAuthType === 'httpQueryAuth') { try { httpQueryAuth = await this.getCredentials('httpQueryAuth'); - } catch (_) {} + } catch {} } else if (genericAuthType === 'oAuth1Api') { try { oAuth1Api = await this.getCredentials('oAuth1Api'); - } catch (_) {} + } catch {} } else if (genericAuthType === 'oAuth2Api') { try { oAuth2Api = await this.getCredentials('oAuth2Api'); - } catch (_) {} + } catch {} } } else if (authentication === 'predefinedCredentialType') { try { nodeCredentialType = this.getNodeParameter('nodeCredentialType', 0) as string; - } catch (_) {} + } catch {} } let requestOptions: OptionsWithUri = { @@ -1110,7 +1110,7 @@ export class HttpRequestV3 implements INodeType { if (typeof jsonBodyParameter !== 'object' && jsonBodyParameter !== null) { try { JSON.parse(jsonBodyParameter); - } catch (_) { + } catch { throw new NodeOperationError( this.getNode(), 'JSON parameter need to be an valid JSON', @@ -1163,7 +1163,7 @@ export class HttpRequestV3 implements INodeType { // query is specified using JSON try { JSON.parse(jsonQueryParameter); - } catch (_) { + } catch { throw new NodeOperationError( this.getNode(), 'JSON parameter need to be an valid JSON', @@ -1188,7 +1188,7 @@ export class HttpRequestV3 implements INodeType { // body is specified using JSON try { JSON.parse(jsonHeadersParameter); - } catch (_) { + } catch { throw new NodeOperationError( this.getNode(), 'JSON parameter need to be an valid JSON', diff --git a/packages/workflow/src/TelemetryHelpers.ts b/packages/workflow/src/TelemetryHelpers.ts index 42a3c52981..69231a167e 100644 --- a/packages/workflow/src/TelemetryHelpers.ts +++ b/packages/workflow/src/TelemetryHelpers.ts @@ -64,7 +64,7 @@ export function getDomainBase(raw: string, urlParts = URL_PARTS_REGEX): string { const url = new URL(raw); return [url.protocol, url.hostname].join('//'); - } catch (_) { + } catch { const match = urlParts.exec(raw); if (!match?.groups?.protocolPlusDomain) return ''; @@ -98,7 +98,7 @@ export function getDomainPath(raw: string, urlParts = URL_PARTS_REGEX): string { if (!url.hostname) throw new Error('Malformed URL'); return sanitizeRoute(url.pathname); - } catch (_) { + } catch { const match = urlParts.exec(raw); if (!match?.groups?.pathname) return ''; @@ -168,7 +168,7 @@ export function generateNodesGraph( if (node.type === 'n8n-nodes-base.httpRequest' && node.typeVersion === 1) { try { nodeItem.domain = new URL(node.parameters.url as string).hostname; - } catch (_) { + } catch { nodeItem.domain = getDomainBase(node.parameters.url as string); } } else if (node.type === 'n8n-nodes-base.httpRequest' && [2, 3].includes(node.typeVersion)) {