mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +00:00
refactor(errors): massaging validation messages before we assign it (#25452)
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
This commit is contained in:
parent
bdabe43094
commit
bece5a1c50
10 changed files with 26 additions and 21 deletions
|
@ -77,7 +77,8 @@ function validateHostRule(rule: LegacyHostRule & HostRule): void {
|
||||||
if (distinctHostValues.size > 1) {
|
if (distinctHostValues.size > 1) {
|
||||||
const error = new Error(CONFIG_VALIDATION);
|
const error = new Error(CONFIG_VALIDATION);
|
||||||
error.validationSource = 'config';
|
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 =
|
error.validationError =
|
||||||
'The renovate configuration file contains some invalid settings';
|
'The renovate configuration file contains some invalid settings';
|
||||||
throw error;
|
throw error;
|
||||||
|
|
|
@ -66,7 +66,7 @@ function replaceSecretsInString(
|
||||||
const error = new Error(CONFIG_VALIDATION);
|
const error = new Error(CONFIG_VALIDATION);
|
||||||
error.validationSource = 'config';
|
error.validationSource = 'config';
|
||||||
error.validationError = 'Disallowed secret substitution';
|
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;
|
throw error;
|
||||||
}
|
}
|
||||||
return value.replace(secretTemplateRegex, (_, secretName) => {
|
return value.replace(secretTemplateRegex, (_, secretName) => {
|
||||||
|
|
|
@ -63,7 +63,7 @@ export function checkForPlatformFailure(err: Error): Error | null {
|
||||||
logger.debug({ err }, 'Converting git error to CONFIG_VALIDATION error');
|
logger.debug({ err }, 'Converting git error to CONFIG_VALIDATION error');
|
||||||
const res = new Error(CONFIG_VALIDATION);
|
const res = new Error(CONFIG_VALIDATION);
|
||||||
res.validationError = message;
|
res.validationError = message;
|
||||||
res.validationMessage = err.message;
|
res.validationMessage = `\`${err.message.replaceAll('`', "'")}\``;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ export function handleCommitError(
|
||||||
const error = new Error(CONFIG_VALIDATION);
|
const error = new Error(CONFIG_VALIDATION);
|
||||||
error.validationSource = 'None';
|
error.validationSource = 'None';
|
||||||
error.validationError = 'An existing branch is blocking Renovate';
|
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;
|
throw error;
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
|
@ -114,9 +114,10 @@ export function handleCommitError(
|
||||||
const error = new Error(CONFIG_VALIDATION);
|
const error = new Error(CONFIG_VALIDATION);
|
||||||
error.validationSource = branchName;
|
error.validationSource = branchName;
|
||||||
error.validationError = 'Bitbucket committer error';
|
error.validationError = 'Bitbucket committer error';
|
||||||
error.validationMessage = `Renovate has experienced the following error when attempting to push its branch to the server: "${String(
|
error.validationMessage = `Renovate has experienced the following error when attempting to push its branch to the server: \`${err.message.replaceAll(
|
||||||
err.message
|
'`',
|
||||||
)}"`;
|
"'"
|
||||||
|
)}\``;
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
if (err.message.includes('remote: error: cannot lock ref')) {
|
if (err.message.includes('remote: error: cannot lock ref')) {
|
||||||
|
|
|
@ -286,7 +286,7 @@ export function setGitAuthor(gitAuthor: string | undefined): void {
|
||||||
const error = new Error(CONFIG_VALIDATION);
|
const error = new Error(CONFIG_VALIDATION);
|
||||||
error.validationSource = 'None';
|
error.validationSource = 'None';
|
||||||
error.validationError = 'Invalid gitAuthor';
|
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;
|
throw error;
|
||||||
}
|
}
|
||||||
config.gitAuthorName = gitAuthorParsed.name;
|
config.gitAuthorName = gitAuthorParsed.name;
|
||||||
|
|
|
@ -732,8 +732,8 @@ describe('util/package-rules/index', () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(error).toStrictEqual(new Error(MISSING_API_CREDENTIALS));
|
expect(error).toStrictEqual(new Error(MISSING_API_CREDENTIALS));
|
||||||
expect(error.validationMessage).toBe('Missing credentials');
|
expect(error.validationError).toBe('Missing credentials');
|
||||||
expect(error.validationError).toBe(
|
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.'
|
'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.'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -18,8 +18,9 @@ export class MergeConfidenceMatcher extends Matcher {
|
||||||
*/
|
*/
|
||||||
if (is.undefined(getApiToken())) {
|
if (is.undefined(getApiToken())) {
|
||||||
const error = new Error(MISSING_API_CREDENTIALS);
|
const error = new Error(MISSING_API_CREDENTIALS);
|
||||||
error.validationMessage = 'Missing credentials';
|
error.validationSource = 'MatchConfidence Authenticator';
|
||||||
error.validationError =
|
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.';
|
'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;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ describe('workers/repository/error-config', () => {
|
||||||
|
|
||||||
Location: \`package.json\`
|
Location: \`package.json\`
|
||||||
Error type: some-error
|
Error type: some-error
|
||||||
Message: \`some-message\`
|
Message: some-message
|
||||||
`;
|
`;
|
||||||
const error = new Error(CONFIG_VALIDATION);
|
const error = new Error(CONFIG_VALIDATION);
|
||||||
error.validationSource = 'package.json';
|
error.validationSource = 'package.json';
|
||||||
|
|
|
@ -3,7 +3,6 @@ import { GlobalConfig } from '../../config/global';
|
||||||
import type { RenovateConfig } from '../../config/types';
|
import type { RenovateConfig } from '../../config/types';
|
||||||
import { logger } from '../../logger';
|
import { logger } from '../../logger';
|
||||||
import { Pr, platform } from '../../modules/platform';
|
import { Pr, platform } from '../../modules/platform';
|
||||||
import { regEx } from '../../util/regex';
|
|
||||||
|
|
||||||
export function raiseConfigWarningIssue(
|
export function raiseConfigWarningIssue(
|
||||||
config: RenovateConfig,
|
config: RenovateConfig,
|
||||||
|
@ -42,10 +41,7 @@ async function raiseWarningIssue(
|
||||||
body += `Error type: ${error.validationError}\n`;
|
body += `Error type: ${error.validationError}\n`;
|
||||||
}
|
}
|
||||||
if (error.validationMessage) {
|
if (error.validationMessage) {
|
||||||
body += `Message: \`${error.validationMessage.replace(
|
body += `Message: ${error.validationMessage}\n`;
|
||||||
regEx(/`/g),
|
|
||||||
"'"
|
|
||||||
)}\`\n`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const pr = await platform.getBranchPr(
|
const pr = await platform.getBranchPr(
|
||||||
|
|
|
@ -140,7 +140,10 @@ export async function detectRepoFileConfig(): Promise<RepoFileConfig> {
|
||||||
'Error parsing renovate config renovate.json5'
|
'Error parsing renovate config renovate.json5'
|
||||||
);
|
);
|
||||||
const validationError = 'Invalid JSON5 (parsing failed)';
|
const validationError = 'Invalid JSON5 (parsing failed)';
|
||||||
const validationMessage = `JSON5.parse error: ${String(err.message)}`;
|
const validationMessage = `JSON5.parse error: \`${err.message.replaceAll(
|
||||||
|
'`',
|
||||||
|
"'"
|
||||||
|
)}\``;
|
||||||
return {
|
return {
|
||||||
configFileName,
|
configFileName,
|
||||||
configFileParseError: { validationError, validationMessage },
|
configFileParseError: { validationError, validationMessage },
|
||||||
|
@ -181,7 +184,10 @@ export async function detectRepoFileConfig(): Promise<RepoFileConfig> {
|
||||||
'Error parsing renovate config'
|
'Error parsing renovate config'
|
||||||
);
|
);
|
||||||
const validationError = 'Invalid JSON (parsing failed)';
|
const validationError = 'Invalid JSON (parsing failed)';
|
||||||
const validationMessage = `JSON.parse error: ${String(err.message)}`;
|
const validationMessage = `JSON.parse error: \`${err.message.replaceAll(
|
||||||
|
'`',
|
||||||
|
"'"
|
||||||
|
)}\``;
|
||||||
return {
|
return {
|
||||||
configFileName,
|
configFileName,
|
||||||
configFileParseError: { validationError, validationMessage },
|
configFileParseError: { validationError, validationMessage },
|
||||||
|
|
|
@ -56,7 +56,7 @@ async function getBaseBranchConfig(
|
||||||
const error = new Error(CONFIG_VALIDATION);
|
const error = new Error(CONFIG_VALIDATION);
|
||||||
error.validationSource = 'config';
|
error.validationSource = 'config';
|
||||||
error.validationError = 'Error fetching config file';
|
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;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue