Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename Error location to validationSource #10018

Merged
merged 1 commit into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions lib/config/presets/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand All @@ -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();
});
Expand All @@ -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();
});
Expand All @@ -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();
});
Expand All @@ -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();
});
Expand All @@ -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();
});
Expand All @@ -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();
});
Expand Down Expand Up @@ -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();
});
Expand All @@ -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();
});
Expand All @@ -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();
});
Expand All @@ -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();
});
Expand Down
4 changes: 2 additions & 2 deletions lib/config/secrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

declare interface Error {
location?: string;
validationSource?: string;

validationError?: string;
validationMessage?: string;
Expand Down
2 changes: 1 addition & 1 deletion lib/manager/npm/extract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lib/util/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/util/regex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/versioning/regex/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class RegExpVersioningApi extends GenericVersioningApi<RegExpVersion> {
!new_config.includes('<patch>')
) {
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;
Expand Down
8 changes: 4 additions & 4 deletions lib/workers/repository/error-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ 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);
expect(res).toBeUndefined();
});
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 });
Expand All @@ -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<Pr>(),
Expand All @@ -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<Pr>(),
Expand Down
4 changes: 2 additions & 2 deletions lib/workers/repository/error-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export async function raiseConfigWarningIssue(
): Promise<void> {
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) {
Expand Down
4 changes: 2 additions & 2 deletions lib/workers/repository/init/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/repository/process/lookup/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: ' +
Expand Down