From f583a9af7614b5b603186f82f4184e37c2b67469 Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Mon, 17 May 2021 09:22:14 +0200 Subject: [PATCH] refactor: rename Error location to validationSource --- lib/config/presets/index.spec.ts | 22 +++++++++---------- lib/config/secrets.ts | 4 ++-- lib/globals.d.ts | 2 +- lib/manager/npm/extract/index.ts | 2 +- lib/util/git/index.ts | 4 ++-- lib/util/regex.ts | 2 +- lib/versioning/regex/index.ts | 2 +- lib/workers/repository/error-config.spec.ts | 8 +++---- lib/workers/repository/error-config.ts | 4 ++-- lib/workers/repository/init/merge.ts | 4 ++-- .../repository/process/lookup/filter.ts | 2 +- 11 files changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/config/presets/index.spec.ts b/lib/config/presets/index.spec.ts index 838c6b528749d2..763cf30f19335e 100644 --- a/lib/config/presets/index.spec.ts +++ b/lib/config/presets/index.spec.ts @@ -62,7 +62,7 @@ describe(getName(), () => { e = err; } expect(e).toBeDefined(); - expect(e.location).toMatchSnapshot(); + expect(e.validationSource).toMatchSnapshot(); expect(e.validationError).toMatchSnapshot(); expect(e.validationMessage).toMatchSnapshot(); }); @@ -76,7 +76,7 @@ describe(getName(), () => { e = err; } expect(e).toBeDefined(); - expect(e.location).toMatchSnapshot(); + expect(e.validationSource).toMatchSnapshot(); expect(e.validationError).toMatchSnapshot(); expect(e.validationMessage).toMatchSnapshot(); }); @@ -91,7 +91,7 @@ describe(getName(), () => { e = err; } expect(e).toBeDefined(); - expect(e.location).toMatchSnapshot(); + expect(e.validationSource).toMatchSnapshot(); expect(e.validationError).toMatchSnapshot(); expect(e.validationMessage).toMatchSnapshot(); }); @@ -106,7 +106,7 @@ describe(getName(), () => { e = err; } expect(e).toBeDefined(); - expect(e.location).toMatchSnapshot(); + expect(e.validationSource).toMatchSnapshot(); expect(e.validationError).toMatchSnapshot(); expect(e.validationMessage).toMatchSnapshot(); }); @@ -121,7 +121,7 @@ describe(getName(), () => { e = err; } expect(e).toBeDefined(); - expect(e.location).toMatchSnapshot(); + expect(e.validationSource).toMatchSnapshot(); expect(e.validationError).toMatchSnapshot(); expect(e.validationMessage).toMatchSnapshot(); }); @@ -136,7 +136,7 @@ describe(getName(), () => { e = err; } expect(e).toBeDefined(); - expect(e.location).toMatchSnapshot(); + expect(e.validationSource).toMatchSnapshot(); expect(e.validationError).toMatchSnapshot(); expect(e.validationMessage).toMatchSnapshot(); }); @@ -159,7 +159,7 @@ describe(getName(), () => { e = err; } expect(e).toBeDefined(); - expect(e.location).toMatchSnapshot(); + expect(e.validationSource).toMatchSnapshot(); expect(e.validationError).toMatchSnapshot(); expect(e.validationMessage).toMatchSnapshot(); }); @@ -430,7 +430,7 @@ describe(getName(), () => { e = err; } expect(e).toBeDefined(); - expect(e.location).toMatchSnapshot(); + expect(e.validationSource).toMatchSnapshot(); expect(e.validationError).toMatchSnapshot(); expect(e.validationMessage).toMatchSnapshot(); }); @@ -442,7 +442,7 @@ describe(getName(), () => { e = err; } expect(e).toBeDefined(); - expect(e.location).toMatchSnapshot(); + expect(e.validationSource).toMatchSnapshot(); expect(e.validationError).toMatchSnapshot(); expect(e.validationMessage).toMatchSnapshot(); }); @@ -454,7 +454,7 @@ describe(getName(), () => { e = err; } expect(e).toBeDefined(); - expect(e.location).toMatchSnapshot(); + expect(e.validationSource).toMatchSnapshot(); expect(e.validationError).toMatchSnapshot(); expect(e.validationMessage).toMatchSnapshot(); }); @@ -466,7 +466,7 @@ describe(getName(), () => { e = err; } expect(e).toBeDefined(); - expect(e.location).toMatchSnapshot(); + expect(e.validationSource).toMatchSnapshot(); expect(e.validationError).toMatchSnapshot(); expect(e.validationMessage).toMatchSnapshot(); }); diff --git a/lib/config/secrets.ts b/lib/config/secrets.ts index 97fbb6c9c3439c..c07a0fc912cab3 100644 --- a/lib/config/secrets.ts +++ b/lib/config/secrets.ts @@ -64,7 +64,7 @@ function replaceSecretsInString( const disallowedPrefixes = ['branch', 'commit', 'group', 'pr', 'semantic']; if (disallowedPrefixes.some((prefix) => key.startsWith(prefix))) { const error = new Error(CONFIG_VALIDATION); - error.location = 'config'; + error.validationSource = 'config'; error.validationError = 'Disallowed secret substitution'; error.validationMessage = `The field ${key} may not use secret substitution`; throw error; @@ -74,7 +74,7 @@ function replaceSecretsInString( return secrets[secretName]; } const error = new Error(CONFIG_VALIDATION); - error.location = 'config'; + error.validationSource = 'config'; error.validationError = 'Unknown secret name'; error.validationMessage = `The following secret name was not found in config: ${String( secretName diff --git a/lib/globals.d.ts b/lib/globals.d.ts index 6edf0241f13c35..eef15fbf1826df 100644 --- a/lib/globals.d.ts +++ b/lib/globals.d.ts @@ -3,7 +3,7 @@ */ declare interface Error { - location?: string; + validationSource?: string; validationError?: string; validationMessage?: string; diff --git a/lib/manager/npm/extract/index.ts b/lib/manager/npm/extract/index.ts index 7521b692ec7210..472c8d07811d83 100644 --- a/lib/manager/npm/extract/index.ts +++ b/lib/manager/npm/extract/index.ts @@ -51,7 +51,7 @@ export async function extractPackageFile( } if (fileName !== 'package.json' && packageJson.renovate) { const error = new Error(CONFIG_VALIDATION); - error.location = fileName; + error.validationSource = fileName; error.validationError = 'Nested package.json must not contain renovate configuration. Please use `packageRules` with `matchPaths` in your main config instead.'; throw error; diff --git a/lib/util/git/index.ts b/lib/util/git/index.ts index bb74bb58b2f13b..db1a25825e372b 100644 --- a/lib/util/git/index.ts +++ b/lib/util/git/index.ts @@ -774,7 +774,7 @@ export async function commitFiles({ checkForPlatformFailure(err); if (err.message.includes(`'refs/heads/renovate' exists`)) { const error = new Error(CONFIG_VALIDATION); - error.location = 'None'; + error.validationSource = 'None'; error.validationError = 'An existing branch is blocking Renovate'; error.validationMessage = `Renovate needs to create the branch "${branchName}" but is blocked from doing so because of an existing branch called "renovate". Please remove it so that Renovate can proceed.`; throw error; @@ -800,7 +800,7 @@ export async function commitFiles({ } if (err.message.includes('protected branch hook declined')) { const error = new Error(CONFIG_VALIDATION); - error.location = branchName; + error.validationSource = branchName; error.validationError = 'Renovate branch is protected'; error.validationMessage = `Renovate cannot push to its branch because branch protection has been enabled.`; throw error; diff --git a/lib/util/regex.ts b/lib/util/regex.ts index c376caae7d94f7..1ece8cf47c4d6c 100644 --- a/lib/util/regex.ts +++ b/lib/util/regex.ts @@ -21,7 +21,7 @@ export function regEx(pattern: string, flags?: string): RegExp { return new RegEx(pattern, flags); } catch (err) { const error = new Error(CONFIG_VALIDATION); - error.location = pattern; + error.validationSource = pattern; error.validationError = `Invalid regular expression: ${pattern}`; throw error; } diff --git a/lib/versioning/regex/index.ts b/lib/versioning/regex/index.ts index e0cedd1c11aaef..9257a41d0a0985 100644 --- a/lib/versioning/regex/index.ts +++ b/lib/versioning/regex/index.ts @@ -55,7 +55,7 @@ export class RegExpVersioningApi extends GenericVersioningApi { !new_config.includes('') ) { const error = new Error(CONFIG_VALIDATION); - error.location = new_config; + error.validationSource = new_config; error.validationError = 'regex versioning needs at least one major, minor or patch group defined'; throw error; diff --git a/lib/workers/repository/error-config.spec.ts b/lib/workers/repository/error-config.spec.ts index f0df8e445ad814..5e7f6b8475c211 100644 --- a/lib/workers/repository/error-config.spec.ts +++ b/lib/workers/repository/error-config.spec.ts @@ -26,7 +26,7 @@ describe(getName(), () => { }); it('creates issues', async () => { const error = new Error(CONFIG_VALIDATION); - error.location = 'package.json'; + error.validationSource = 'package.json'; error.validationMessage = 'some-message'; platform.ensureIssue.mockResolvedValueOnce('created'); const res = await raiseConfigWarningIssue(config, error); @@ -34,7 +34,7 @@ describe(getName(), () => { }); it('creates issues (dryRun)', async () => { const error = new Error(CONFIG_VALIDATION); - error.location = 'package.json'; + error.validationSource = 'package.json'; error.validationMessage = 'some-message'; platform.ensureIssue.mockResolvedValueOnce('created'); setAdminConfig({ dryRun: true }); @@ -43,7 +43,7 @@ describe(getName(), () => { }); it('handles onboarding', async () => { const error = new Error(CONFIG_VALIDATION); - error.location = 'package.json'; + error.validationSource = 'package.json'; error.validationMessage = 'some-message'; platform.getBranchPr.mockResolvedValue({ ...mock(), @@ -55,7 +55,7 @@ describe(getName(), () => { }); it('handles onboarding (dryRun)', async () => { const error = new Error(CONFIG_VALIDATION); - error.location = 'package.json'; + error.validationSource = 'package.json'; error.validationMessage = 'some-message'; platform.getBranchPr.mockResolvedValue({ ...mock(), diff --git a/lib/workers/repository/error-config.ts b/lib/workers/repository/error-config.ts index f26bfb41876a7b..8b12091fb1540e 100644 --- a/lib/workers/repository/error-config.ts +++ b/lib/workers/repository/error-config.ts @@ -10,8 +10,8 @@ export async function raiseConfigWarningIssue( ): Promise { logger.debug('raiseConfigWarningIssue()'); let body = `There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.\n\n`; - if (error.location) { - body += `Location: \`${error.location}\`\n`; + if (error.validationSource) { + body += `Location: \`${error.validationSource}\`\n`; } body += `Error type: ${error.validationError}\n`; if (error.validationMessage) { diff --git a/lib/workers/repository/init/merge.ts b/lib/workers/repository/init/merge.ts index 8529f45f39ac98..95cb880088909d 100644 --- a/lib/workers/repository/init/merge.ts +++ b/lib/workers/repository/init/merge.ts @@ -136,7 +136,7 @@ export function checkForRepoConfigError(repoConfig: RepoFileConfig): void { return; } const error = new Error(CONFIG_VALIDATION); - error.location = repoConfig.configFileName; + error.validationSource = repoConfig.configFileName; error.validationError = repoConfig.configFileParseError.validationError; error.validationMessage = repoConfig.configFileParseError.validationMessage; throw error; @@ -160,7 +160,7 @@ export async function mergeRenovateConfig( const migratedConfig = await migrateAndValidate(config, configFileParsed); if (migratedConfig.errors.length) { const error = new Error(CONFIG_VALIDATION); - error.location = repoConfig.configFileName; + error.validationSource = repoConfig.configFileName; error.validationError = 'The renovate configuration file contains some invalid settings'; error.validationMessage = migratedConfig.errors diff --git a/lib/workers/repository/process/lookup/filter.ts b/lib/workers/repository/process/lookup/filter.ts index bfe7f996a9e887..f3331df1be33a7 100644 --- a/lib/workers/repository/process/lookup/filter.ts +++ b/lib/workers/repository/process/lookup/filter.ts @@ -98,7 +98,7 @@ export function filterVersions( ); } else { const error = new Error(CONFIG_VALIDATION); - error.location = 'config'; + error.validationSource = 'config'; error.validationError = 'Invalid `allowedVersions`'; error.validationMessage = 'The following allowedVersions does not parse as a valid version or range: ' +