diff --git a/lib/config/migrations/custom/host-rules-migration.ts b/lib/config/migrations/custom/host-rules-migration.ts index b773828813cb92f1818f5ac2e34bf70b26b3f799..bcf064fe13ffc161cf6a7b458cea72c72483474f 100644 --- a/lib/config/migrations/custom/host-rules-migration.ts +++ b/lib/config/migrations/custom/host-rules-migration.ts @@ -77,7 +77,8 @@ function validateHostRule(rule: LegacyHostRule & HostRule): void { if (distinctHostValues.size > 1) { const error = new Error(CONFIG_VALIDATION); error.validationSource = 'config'; - error.validationMessage = `hostRules cannot contain more than one host-matching field - use "matchHost" only.`; + error.validationMessage = + '`hostRules` cannot contain more than one host-matching field - use `matchHost` only.'; error.validationError = 'The renovate configuration file contains some invalid settings'; throw error; diff --git a/lib/config/secrets.ts b/lib/config/secrets.ts index 3198a99b32e9747bfaa521235c7378e925342f71..874afe29a70f61e3452412db5e0e49ca90f78c9f 100644 --- a/lib/config/secrets.ts +++ b/lib/config/secrets.ts @@ -66,7 +66,7 @@ function replaceSecretsInString( const error = new Error(CONFIG_VALIDATION); error.validationSource = 'config'; error.validationError = 'Disallowed secret substitution'; - error.validationMessage = `The field ${key} may not use secret substitution`; + error.validationMessage = `The field \`${key}\` may not use secret substitution`; throw error; } return value.replace(secretTemplateRegex, (_, secretName) => { diff --git a/lib/util/git/error.ts b/lib/util/git/error.ts index cd9e80e21d5730893411c1ebf238f9fe1bbaa577..34708669f3012a0e0d58ab8f9dea6906699d937e 100644 --- a/lib/util/git/error.ts +++ b/lib/util/git/error.ts @@ -63,7 +63,7 @@ export function checkForPlatformFailure(err: Error): Error | null { logger.debug({ err }, 'Converting git error to CONFIG_VALIDATION error'); const res = new Error(CONFIG_VALIDATION); res.validationError = message; - res.validationMessage = err.message; + res.validationMessage = `\`${err.message.replaceAll('`', "'")}\``; return res; } } @@ -82,7 +82,7 @@ export function handleCommitError( const error = new Error(CONFIG_VALIDATION); 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.`; + 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; } if ( @@ -114,9 +114,10 @@ export function handleCommitError( const error = new Error(CONFIG_VALIDATION); error.validationSource = branchName; error.validationError = 'Bitbucket committer error'; - error.validationMessage = `Renovate has experienced the following error when attempting to push its branch to the server: "${String( - err.message - )}"`; + error.validationMessage = `Renovate has experienced the following error when attempting to push its branch to the server: \`${err.message.replaceAll( + '`', + "'" + )}\``; throw error; } if (err.message.includes('remote: error: cannot lock ref')) { diff --git a/lib/util/git/index.ts b/lib/util/git/index.ts index c919e559efeb1b14c745435263413f590caa44e9..ce68362dc9539013509222c557d22d59dce6d964 100644 --- a/lib/util/git/index.ts +++ b/lib/util/git/index.ts @@ -286,7 +286,7 @@ export function setGitAuthor(gitAuthor: string | undefined): void { const error = new Error(CONFIG_VALIDATION); error.validationSource = 'None'; error.validationError = 'Invalid gitAuthor'; - error.validationMessage = `gitAuthor is not parsed as valid RFC5322 format: ${gitAuthor!}`; + error.validationMessage = `\`gitAuthor\` is not parsed as valid RFC5322 format: \`${gitAuthor!}\``; throw error; } config.gitAuthorName = gitAuthorParsed.name; diff --git a/lib/util/package-rules/index.spec.ts b/lib/util/package-rules/index.spec.ts index 195425fa026ba623a5da9a0e9474c3529e6592a2..34a70e8fd8460421d3d7b485befddecb487a093d 100644 --- a/lib/util/package-rules/index.spec.ts +++ b/lib/util/package-rules/index.spec.ts @@ -732,8 +732,8 @@ describe('util/package-rules/index', () => { } expect(error).toStrictEqual(new Error(MISSING_API_CREDENTIALS)); - expect(error.validationMessage).toBe('Missing credentials'); - expect(error.validationError).toBe( + expect(error.validationError).toBe('Missing credentials'); + expect(error.validationMessage).toBe( 'The `matchConfidence` matcher in `packageRules` requires authentication. Please refer to the [documentation](https://docs.renovatebot.com/configuration-options/#matchconfidence) and add the required host rule.' ); }); diff --git a/lib/util/package-rules/merge-confidence.ts b/lib/util/package-rules/merge-confidence.ts index 9836892f497e479b8368e9751b1c46884cc24d29..edd87429b8d12bd760e37a68ec10f8aec3542b33 100644 --- a/lib/util/package-rules/merge-confidence.ts +++ b/lib/util/package-rules/merge-confidence.ts @@ -18,8 +18,9 @@ export class MergeConfidenceMatcher extends Matcher { */ if (is.undefined(getApiToken())) { const error = new Error(MISSING_API_CREDENTIALS); - error.validationMessage = 'Missing credentials'; - error.validationError = + error.validationSource = 'MatchConfidence Authenticator'; + error.validationError = 'Missing credentials'; + error.validationMessage = 'The `matchConfidence` matcher in `packageRules` requires authentication. Please refer to the [documentation](https://docs.renovatebot.com/configuration-options/#matchconfidence) and add the required host rule.'; throw error; } diff --git a/lib/workers/repository/error-config.spec.ts b/lib/workers/repository/error-config.spec.ts index 7731fb58c206c42152395fbc7b4f235c4038f8c9..b37abdd4be65d48ffe3b0500a86b4f235f246d79 100644 --- a/lib/workers/repository/error-config.spec.ts +++ b/lib/workers/repository/error-config.spec.ts @@ -34,7 +34,7 @@ describe('workers/repository/error-config', () => { Location: \`package.json\` Error type: some-error -Message: \`some-message\` +Message: some-message `; const error = new Error(CONFIG_VALIDATION); error.validationSource = 'package.json'; diff --git a/lib/workers/repository/error-config.ts b/lib/workers/repository/error-config.ts index f7b62dda01d5beb07798b6a2319f613c9088264f..24f04c4e3a3130714c43481a7fc722f51199d7a8 100644 --- a/lib/workers/repository/error-config.ts +++ b/lib/workers/repository/error-config.ts @@ -3,7 +3,6 @@ import { GlobalConfig } from '../../config/global'; import type { RenovateConfig } from '../../config/types'; import { logger } from '../../logger'; import { Pr, platform } from '../../modules/platform'; -import { regEx } from '../../util/regex'; export function raiseConfigWarningIssue( config: RenovateConfig, @@ -42,10 +41,7 @@ async function raiseWarningIssue( body += `Error type: ${error.validationError}\n`; } if (error.validationMessage) { - body += `Message: \`${error.validationMessage.replace( - regEx(/`/g), - "'" - )}\`\n`; + body += `Message: ${error.validationMessage}\n`; } const pr = await platform.getBranchPr( diff --git a/lib/workers/repository/init/merge.ts b/lib/workers/repository/init/merge.ts index a244b768ae54527fb9eb8415ee4eddb5564623ce..a0233d22e5594afcc0a75db55fec61ee212480eb 100644 --- a/lib/workers/repository/init/merge.ts +++ b/lib/workers/repository/init/merge.ts @@ -140,7 +140,10 @@ export async function detectRepoFileConfig(): Promise<RepoFileConfig> { 'Error parsing renovate config renovate.json5' ); const validationError = 'Invalid JSON5 (parsing failed)'; - const validationMessage = `JSON5.parse error: ${String(err.message)}`; + const validationMessage = `JSON5.parse error: \`${err.message.replaceAll( + '`', + "'" + )}\``; return { configFileName, configFileParseError: { validationError, validationMessage }, @@ -181,7 +184,10 @@ export async function detectRepoFileConfig(): Promise<RepoFileConfig> { 'Error parsing renovate config' ); const validationError = 'Invalid JSON (parsing failed)'; - const validationMessage = `JSON.parse error: ${String(err.message)}`; + const validationMessage = `JSON.parse error: \`${err.message.replaceAll( + '`', + "'" + )}\``; return { configFileName, configFileParseError: { validationError, validationMessage }, diff --git a/lib/workers/repository/process/index.ts b/lib/workers/repository/process/index.ts index 39b8e76fa894922ea073b4fdecfdaae6650498b0..ff10492c10c7f5febd87b2883e56371d3badc19f 100644 --- a/lib/workers/repository/process/index.ts +++ b/lib/workers/repository/process/index.ts @@ -56,7 +56,7 @@ async function getBaseBranchConfig( const error = new Error(CONFIG_VALIDATION); error.validationSource = 'config'; error.validationError = 'Error fetching config file'; - error.validationMessage = `Error fetching config file ${configFileName} from branch ${baseBranch}`; + error.validationMessage = `Error fetching config file \`${configFileName}\` from branch \`${baseBranch}\``; throw error; }