Skip to content

Commit

Permalink
feat(internal): expand disabled error messages
Browse files Browse the repository at this point in the history
Splits REPOSITORY_DISABLED into multiple
  • Loading branch information
rarkins committed Feb 11, 2021
1 parent 89ed1c5 commit fa9031f
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 41 deletions.
15 changes: 10 additions & 5 deletions lib/constants/error-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,30 @@ export const PLATFORM_RATE_LIMIT_EXCEEDED = 'rate-limit-exceeded';
export const CONFIG_VALIDATION = 'config-validation';
export const CONFIG_SECRETS_EXPOSED = 'config-secrets-exposed';

// Repository Error
// Repository Errors - causes repo to be considered as disabled
export const REPOSITORY_ACCESS_FORBIDDEN = 'forbidden';
export const REPOSITORY_ARCHIVED = 'archived';
export const REPOSITORY_BLOCKED = 'blocked';
export const REPOSITORY_CANNOT_FORK = 'cannot-fork';
export const REPOSITORY_CHANGED = 'repository-changed';
export const REPOSITORY_DISABLED = 'disabled';
export const REPOSITORY_CLOSED_ONBOARDING = 'disabled-closed-onboarding';
export const REPOSITORY_DISABLED_BY_CONFIG = 'disabled-by-config';
export const REPOSITORY_NO_CONFIG = 'disabled-no-config';
export const REPOSITORY_EMPTY = 'empty';
export const REPOSITORY_FORKED = 'fork';
export const REPOSITORY_MIRRORED = 'mirror';
export const REPOSITORY_NOT_FOUND = 'not-found';
export const REPOSITORY_NO_VULNERABILITY = 'no-vulnerability-alerts';
export const REPOSITORY_NO_PACKAGE_FILES = 'no-package-files';
export const REPOSITORY_RENAMED = 'renamed';
export const REPOSITORY_TEMPORARY_ERROR = 'temporary-error';
export const REPOSITORY_UNINITIATED = 'uninitiated';

// Temporary Error
export const REPOSITORY_CHANGED = 'repository-changed';
export const TEMPORARY_ERROR = 'temporary-error';
export const NO_VULNERABILITY_ALERTS = 'no-vulnerability-alerts';

// Manager Error
export const MANAGER_LOCKFILE_ERROR = 'lockfile-error';
export const MANAGER_NO_PACKAGE_FILES = 'no-package-files';

// Host error
export const EXTERNAL_HOST_ERROR = 'external-host-error';
Expand Down
4 changes: 2 additions & 2 deletions lib/platform/gitlab/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
REPOSITORY_EMPTY,
REPOSITORY_MIRRORED,
REPOSITORY_NOT_FOUND,
REPOSITORY_TEMPORARY_ERROR,
TEMPORARY_ERROR,
} from '../../constants/error-messages';
import { PLATFORM_TYPE_GITLAB } from '../../constants/platforms';
import { logger } from '../../logger';
Expand Down Expand Up @@ -202,7 +202,7 @@ export async function initRepo({
// istanbul ignore if
if (!config.defaultBranch) {
logger.warn({ resBody: res.body }, 'Error fetching GitLab project');
throw new Error(REPOSITORY_TEMPORARY_ERROR);
throw new Error(TEMPORARY_ERROR);
}
config.mergeMethod = res.body.merge_method || 'merge';
logger.debug(`${repository} default branch = ${config.defaultBranch}`);
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 @@ -14,8 +14,8 @@ import {
REPOSITORY_CHANGED,
REPOSITORY_DISABLED,
REPOSITORY_EMPTY,
REPOSITORY_TEMPORARY_ERROR,
SYSTEM_INSUFFICIENT_DISK_SPACE,
TEMPORARY_ERROR,
} from '../../constants/error-messages';
import { logger } from '../../logger';
import { ExternalHostError } from '../../types/errors/external-host-error';
Expand Down Expand Up @@ -324,7 +324,7 @@ export async function syncGit(): Promise<void> {
} catch (err) /* istanbul ignore next */ {
checkForPlatformFailure(err);
logger.debug({ err }, 'Error setting git author config');
throw new Error(REPOSITORY_TEMPORARY_ERROR);
throw new Error(TEMPORARY_ERROR);
}
config.currentBranch = config.currentBranch || (await getDefaultBranch(git));
if (config.branchPrefix) {
Expand Down
4 changes: 2 additions & 2 deletions lib/workers/repository/configured.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { RenovateConfig } from '../../config';
import {
REPOSITORY_DISABLED,
REPOSITORY_DISABLED_BY_CONFIG,
REPOSITORY_FORKED,
} from '../../constants/error-messages';

export function checkIfConfigured(config: RenovateConfig): void {
if (config.enabled === false) {
throw new Error(REPOSITORY_DISABLED);
throw new Error(REPOSITORY_DISABLED_BY_CONFIG);
}
if (config.isFork && !config.includeForks) {
throw new Error(REPOSITORY_FORKED);
Expand Down
14 changes: 7 additions & 7 deletions lib/workers/repository/error.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
CONFIG_VALIDATION,
EXTERNAL_HOST_ERROR,
MANAGER_LOCKFILE_ERROR,
MANAGER_NO_PACKAGE_FILES,
NO_VULNERABILITY_ALERTS,
PLATFORM_AUTHENTICATION_ERROR,
PLATFORM_BAD_CREDENTIALS,
PLATFORM_INTEGRATION_UNAUTHORIZED,
Expand All @@ -19,12 +19,12 @@ import {
REPOSITORY_FORKED,
REPOSITORY_MIRRORED,
REPOSITORY_NOT_FOUND,
REPOSITORY_NO_VULNERABILITY,
REPOSITORY_NO_PACKAGE_FILES,
REPOSITORY_RENAMED,
REPOSITORY_TEMPORARY_ERROR,
REPOSITORY_UNINITIATED,
SYSTEM_INSUFFICIENT_DISK_SPACE,
SYSTEM_INSUFFICIENT_MEMORY,
TEMPORARY_ERROR,
UNKNOWN_ERROR,
} from '../../constants/error-messages';
import { ExternalHostError } from '../../types/errors/external-host-error';
Expand All @@ -46,7 +46,7 @@ describe('workers/repository/error', () => {
REPOSITORY_DISABLED,
REPOSITORY_CHANGED,
REPOSITORY_FORKED,
MANAGER_NO_PACKAGE_FILES,
REPOSITORY_NO_PACKAGE_FILES,
CONFIG_SECRETS_EXPOSED,
CONFIG_VALIDATION,
REPOSITORY_ARCHIVED,
Expand All @@ -60,11 +60,11 @@ describe('workers/repository/error', () => {
MANAGER_LOCKFILE_ERROR,
SYSTEM_INSUFFICIENT_DISK_SPACE,
SYSTEM_INSUFFICIENT_MEMORY,
REPOSITORY_NO_VULNERABILITY,
NO_VULNERABILITY_ALERTS,
REPOSITORY_CANNOT_FORK,
PLATFORM_INTEGRATION_UNAUTHORIZED,
PLATFORM_AUTHENTICATION_ERROR,
REPOSITORY_TEMPORARY_ERROR,
TEMPORARY_ERROR,
];
errors.forEach((err) => {
it(`errors ${err}`, async () => {
Expand Down Expand Up @@ -98,7 +98,7 @@ describe('workers/repository/error', () => {
'fatal: not a git repository (or any parent up to mount point /mnt)\nStopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).\n'
);
const res = await handleError(config, gitError);
expect(res).toEqual(REPOSITORY_TEMPORARY_ERROR);
expect(res).toEqual(TEMPORARY_ERROR);
});
it('handles unknown error', async () => {
const res = await handleError(config, new Error('abcdefg'));
Expand Down
14 changes: 7 additions & 7 deletions lib/workers/repository/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
CONFIG_VALIDATION,
EXTERNAL_HOST_ERROR,
MANAGER_LOCKFILE_ERROR,
MANAGER_NO_PACKAGE_FILES,
NO_VULNERABILITY_ALERTS,
PLATFORM_AUTHENTICATION_ERROR,
PLATFORM_BAD_CREDENTIALS,
PLATFORM_INTEGRATION_UNAUTHORIZED,
Expand All @@ -20,12 +20,12 @@ import {
REPOSITORY_FORKED,
REPOSITORY_MIRRORED,
REPOSITORY_NOT_FOUND,
REPOSITORY_NO_VULNERABILITY,
REPOSITORY_NO_PACKAGE_FILES,
REPOSITORY_RENAMED,
REPOSITORY_TEMPORARY_ERROR,
REPOSITORY_UNINITIATED,
SYSTEM_INSUFFICIENT_DISK_SPACE,
SYSTEM_INSUFFICIENT_MEMORY,
TEMPORARY_ERROR,
UNKNOWN_ERROR,
} from '../../constants/error-messages';
import { logger } from '../../logger';
Expand Down Expand Up @@ -88,11 +88,11 @@ export default async function handleError(
logger.info('Cannot fork repository - skipping');
return err.message;
}
if (err.message === MANAGER_NO_PACKAGE_FILES) {
if (err.message === REPOSITORY_NO_PACKAGE_FILES) {
logger.info('Repository has no package files - skipping');
return err.message;
}
if (err.message === REPOSITORY_NO_VULNERABILITY) {
if (err.message === NO_VULNERABILITY_ALERTS) {
logger.info('Repository has no vulnerability alerts - skipping');
return err.message;
}
Expand Down Expand Up @@ -157,7 +157,7 @@ export default async function handleError(
delete config.branchList; // eslint-disable-line no-param-reassign
return err.message;
}
if (err.message === REPOSITORY_TEMPORARY_ERROR) {
if (err.message === TEMPORARY_ERROR) {
logger.info('Temporary error - aborting');
delete config.branchList; // eslint-disable-line no-param-reassign
return err.message;
Expand Down Expand Up @@ -185,7 +185,7 @@ export default async function handleError(
}
if (err.message.includes('fatal: not a git repository')) {
delete config.branchList; // eslint-disable-line no-param-reassign
return REPOSITORY_TEMPORARY_ERROR;
return TEMPORARY_ERROR;
}
// Swallow this error so that other repositories can be processed
logger.error({ err }, `Repository has unknown error`);
Expand Down
4 changes: 2 additions & 2 deletions lib/workers/repository/init/apis.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RenovateConfig } from '../../../config';
import { configFileNames } from '../../../config/app-strings';
import {
REPOSITORY_DISABLED,
REPOSITORY_DISABLED_BY_CONFIG,
REPOSITORY_FORKED,
} from '../../../constants/error-messages';
import * as npmApi from '../../../datasource/npm';
Expand All @@ -25,7 +25,7 @@ async function validateOptimizeForDisabled(
defaultConfigFile(config)
);
if (renovateConfig?.enabled === false) {
throw new Error(REPOSITORY_DISABLED);
throw new Error(REPOSITORY_DISABLED_BY_CONFIG);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/workers/repository/init/vulnerability.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
partial,
platform,
} from '../../../../test/util';
import { REPOSITORY_NO_VULNERABILITY } from '../../../constants/error-messages';
import { NO_VULNERABILITY_ALERTS } from '../../../constants/error-messages';
import { VulnerabilityAlert } from '../../../types';
import { detectVulnerabilityAlerts } from './vulnerability';

Expand Down Expand Up @@ -33,7 +33,7 @@ describe('workers/repository/init/vulnerability', () => {
config.vulnerabilityAlertsOnly = true;
platform.getVulnerabilityAlerts.mockResolvedValue([]);
await expect(detectVulnerabilityAlerts(config)).rejects.toThrow(
REPOSITORY_NO_VULNERABILITY
NO_VULNERABILITY_ALERTS
);
});
it('returns alerts', async () => {
Expand Down
4 changes: 2 additions & 2 deletions lib/workers/repository/init/vulnerability.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RenovateConfig } from '../../../config';
import { REPOSITORY_NO_VULNERABILITY } from '../../../constants/error-messages';
import { NO_VULNERABILITY_ALERTS } from '../../../constants/error-messages';
import * as datasourceMaven from '../../../datasource/maven';
import * as datasourceNpm from '../../../datasource/npm';
import * as datasourceNuget from '../../../datasource/nuget';
Expand Down Expand Up @@ -43,7 +43,7 @@ export async function detectVulnerabilityAlerts(
if (!alerts.length) {
logger.debug('No vulnerability alerts found');
if (input.vulnerabilityAlertsOnly) {
throw new Error(REPOSITORY_NO_VULNERABILITY);
throw new Error(NO_VULNERABILITY_ALERTS);
}
return input;
}
Expand Down
9 changes: 6 additions & 3 deletions lib/workers/repository/onboarding/branch/check.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { RenovateConfig } from '../../../../config';
import { configFileNames } from '../../../../config/app-strings';
import { REPOSITORY_DISABLED } from '../../../../constants/error-messages';
import {
REPOSITORY_CLOSED_ONBOARDING,
REPOSITORY_NO_CONFIG,
} from '../../../../constants/error-messages';
import { logger } from '../../../../logger';
import { platform } from '../../../../platform';
import { PrState } from '../../../../types';
Expand Down Expand Up @@ -68,7 +71,7 @@ export const isOnboarded = async (config: RenovateConfig): Promise<boolean> => {
// If onboarding has been disabled and config files are required then the
// repository has not been onboarded yet
if (config.requireConfig && config.onboarding === false) {
throw new Error(REPOSITORY_DISABLED);
throw new Error(REPOSITORY_NO_CONFIG);
}

const pr = await closedPrExists(config);
Expand All @@ -90,7 +93,7 @@ export const isOnboarded = async (config: RenovateConfig): Promise<boolean> => {
content: `Renovate is disabled due to lack of config. If you wish to reenable it, you can either (a) commit a config file to your base branch, or (b) rename this closed PR to trigger a replacement onboarding PR.`,
});
}
throw new Error(REPOSITORY_DISABLED);
throw new Error(REPOSITORY_CLOSED_ONBOARDING);
};

export const onboardingPrExists = async (
Expand Down
4 changes: 2 additions & 2 deletions lib/workers/repository/onboarding/branch/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { RenovateConfig } from '../../../../config';
import { getAdminConfig } from '../../../../config/admin';
import {
MANAGER_NO_PACKAGE_FILES,
REPOSITORY_FORKED,
REPOSITORY_NO_PACKAGE_FILES,
} from '../../../../constants/error-messages';
import { logger } from '../../../../logger';
import { platform } from '../../../../platform';
Expand Down Expand Up @@ -43,7 +43,7 @@ export async function checkOnboardingBranch(
} else {
logger.debug('Onboarding PR does not exist');
if (Object.entries(await extractAllDependencies(config)).length === 0) {
throw new Error(MANAGER_NO_PACKAGE_FILES);
throw new Error(REPOSITORY_NO_PACKAGE_FILES);
}
logger.debug('Need to create onboarding PR');
const commit = await createOnboardingBranch(config);
Expand Down
16 changes: 11 additions & 5 deletions lib/workers/repository/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ import { RenovateConfig } from '../../config';
import {
CONFIG_SECRETS_EXPOSED,
CONFIG_VALIDATION,
MANAGER_NO_PACKAGE_FILES,
REPOSITORY_ACCESS_FORBIDDEN,
REPOSITORY_ARCHIVED,
REPOSITORY_BLOCKED,
REPOSITORY_CANNOT_FORK,
REPOSITORY_CLOSED_ONBOARDING,
REPOSITORY_DISABLED,
REPOSITORY_DISABLED_BY_CONFIG,
REPOSITORY_EMPTY,
REPOSITORY_FORKED,
REPOSITORY_MIRRORED,
REPOSITORY_NOT_FOUND,
REPOSITORY_NO_CONFIG,
REPOSITORY_NO_PACKAGE_FILES,
REPOSITORY_RENAMED,
REPOSITORY_UNINITIATED,
} from '../../constants/error-messages';
Expand All @@ -30,18 +33,21 @@ export function processResult(
res: string
): ProcessResult {
const disabledStatuses = [
REPOSITORY_ACCESS_FORBIDDEN,
REPOSITORY_ARCHIVED,
REPOSITORY_BLOCKED,
REPOSITORY_CANNOT_FORK,
REPOSITORY_CLOSED_ONBOARDING,
REPOSITORY_DISABLED,
REPOSITORY_ACCESS_FORBIDDEN,
REPOSITORY_DISABLED_BY_CONFIG,
REPOSITORY_EMPTY,
REPOSITORY_FORKED,
REPOSITORY_MIRRORED,
MANAGER_NO_PACKAGE_FILES,
REPOSITORY_NOT_FOUND,
REPOSITORY_NO_CONFIG,
REPOSITORY_NO_PACKAGE_FILES,
REPOSITORY_RENAMED,
REPOSITORY_UNINITIATED,
REPOSITORY_EMPTY,
REPOSITORY_NOT_FOUND,
];
const enabledStatuses = [CONFIG_SECRETS_EXPOSED, CONFIG_VALIDATION];
let status: ProcessStatus;
Expand Down

0 comments on commit fa9031f

Please sign in to comment.