2021-04-20 08:52:57 +00:00
|
|
|
import type { RenovateConfig } from '../../config/types';
|
2017-12-18 08:39:52 +00:00
|
|
|
|
2020-01-12 07:50:11 +00:00
|
|
|
import {
|
2020-07-03 14:52:16 +00:00
|
|
|
CONFIG_SECRETS_EXPOSED,
|
2020-01-12 07:50:11 +00:00
|
|
|
CONFIG_VALIDATION,
|
2020-06-22 19:28:02 +00:00
|
|
|
EXTERNAL_HOST_ERROR,
|
2020-01-12 07:50:11 +00:00
|
|
|
MANAGER_LOCKFILE_ERROR,
|
2021-02-11 12:32:29 +00:00
|
|
|
NO_VULNERABILITY_ALERTS,
|
2020-01-12 07:50:11 +00:00
|
|
|
PLATFORM_AUTHENTICATION_ERROR,
|
|
|
|
PLATFORM_BAD_CREDENTIALS,
|
|
|
|
PLATFORM_INTEGRATION_UNAUTHORIZED,
|
|
|
|
PLATFORM_RATE_LIMIT_EXCEEDED,
|
|
|
|
REPOSITORY_ACCESS_FORBIDDEN,
|
|
|
|
REPOSITORY_ARCHIVED,
|
|
|
|
REPOSITORY_BLOCKED,
|
|
|
|
REPOSITORY_CANNOT_FORK,
|
|
|
|
REPOSITORY_CHANGED,
|
2021-02-11 16:10:20 +00:00
|
|
|
REPOSITORY_CLOSED_ONBOARDING,
|
2020-01-12 07:50:11 +00:00
|
|
|
REPOSITORY_DISABLED,
|
2021-02-11 16:10:20 +00:00
|
|
|
REPOSITORY_DISABLED_BY_CONFIG,
|
2020-01-12 07:50:11 +00:00
|
|
|
REPOSITORY_EMPTY,
|
|
|
|
REPOSITORY_FORKED,
|
|
|
|
REPOSITORY_MIRRORED,
|
|
|
|
REPOSITORY_NOT_FOUND,
|
2021-02-11 16:10:20 +00:00
|
|
|
REPOSITORY_NO_CONFIG,
|
2021-02-11 12:32:29 +00:00
|
|
|
REPOSITORY_NO_PACKAGE_FILES,
|
2020-01-12 07:50:11 +00:00
|
|
|
REPOSITORY_RENAMED,
|
|
|
|
REPOSITORY_UNINITIATED,
|
|
|
|
SYSTEM_INSUFFICIENT_DISK_SPACE,
|
2020-04-16 16:08:53 +00:00
|
|
|
SYSTEM_INSUFFICIENT_MEMORY,
|
2021-02-11 12:32:29 +00:00
|
|
|
TEMPORARY_ERROR,
|
2020-01-12 07:50:11 +00:00
|
|
|
UNKNOWN_ERROR,
|
|
|
|
} from '../../constants/error-messages';
|
2020-05-01 16:03:48 +00:00
|
|
|
import { logger } from '../../logger';
|
2020-06-23 09:44:52 +00:00
|
|
|
import { ExternalHostError } from '../../types/errors/external-host-error';
|
2020-05-01 16:03:48 +00:00
|
|
|
import { raiseConfigWarningIssue } from './error-config';
|
2020-01-12 07:50:11 +00:00
|
|
|
|
2020-01-10 10:35:49 +00:00
|
|
|
export default async function handleError(
|
|
|
|
config: RenovateConfig,
|
|
|
|
err: Error
|
|
|
|
): Promise<string> {
|
2020-01-12 07:50:11 +00:00
|
|
|
if (err.message === REPOSITORY_UNINITIATED) {
|
2017-11-05 04:45:49 +00:00
|
|
|
logger.info('Repository is uninitiated - skipping');
|
2021-11-08 19:20:03 +00:00
|
|
|
delete config.branchList;
|
2017-11-05 04:45:49 +00:00
|
|
|
return err.message;
|
2018-07-09 09:28:33 +00:00
|
|
|
}
|
2020-01-12 07:50:11 +00:00
|
|
|
if (err.message === REPOSITORY_EMPTY) {
|
2018-09-25 06:50:47 +00:00
|
|
|
logger.info('Repository is empty - skipping');
|
2021-11-08 19:20:03 +00:00
|
|
|
delete config.branchList;
|
2018-09-25 06:50:47 +00:00
|
|
|
return err.message;
|
|
|
|
}
|
2021-02-11 16:10:20 +00:00
|
|
|
const disabledMessages = [
|
|
|
|
REPOSITORY_CLOSED_ONBOARDING,
|
|
|
|
REPOSITORY_DISABLED,
|
|
|
|
REPOSITORY_DISABLED_BY_CONFIG,
|
|
|
|
REPOSITORY_NO_CONFIG,
|
|
|
|
];
|
|
|
|
if (disabledMessages.includes(err.message)) {
|
2017-11-05 04:45:49 +00:00
|
|
|
logger.info('Repository is disabled - skipping');
|
|
|
|
return err.message;
|
2018-07-09 09:28:33 +00:00
|
|
|
}
|
2020-01-12 07:50:11 +00:00
|
|
|
if (err.message === REPOSITORY_ARCHIVED) {
|
2017-12-31 19:28:22 +00:00
|
|
|
logger.info('Repository is archived - skipping');
|
2021-11-08 19:20:03 +00:00
|
|
|
delete config.branchList;
|
2018-02-08 15:04:25 +00:00
|
|
|
return err.message;
|
2018-07-09 09:28:33 +00:00
|
|
|
}
|
2020-01-12 07:50:11 +00:00
|
|
|
if (err.message === REPOSITORY_MIRRORED) {
|
2019-06-13 04:05:58 +00:00
|
|
|
logger.info('Repository is a mirror - skipping');
|
2021-11-08 19:20:03 +00:00
|
|
|
delete config.branchList;
|
2019-06-13 04:05:58 +00:00
|
|
|
return err.message;
|
|
|
|
}
|
2020-01-12 07:50:11 +00:00
|
|
|
if (err.message === REPOSITORY_RENAMED) {
|
2018-02-08 15:04:25 +00:00
|
|
|
logger.info('Repository has been renamed - skipping');
|
2021-11-08 19:20:03 +00:00
|
|
|
delete config.branchList;
|
2017-12-31 19:28:22 +00:00
|
|
|
return err.message;
|
2018-07-09 09:28:33 +00:00
|
|
|
}
|
2020-01-12 07:50:11 +00:00
|
|
|
if (err.message === REPOSITORY_BLOCKED) {
|
2021-11-08 19:20:03 +00:00
|
|
|
delete config.branchList;
|
2018-02-02 17:04:26 +00:00
|
|
|
logger.info('Repository is blocked - skipping');
|
|
|
|
return err.message;
|
2018-07-09 09:28:33 +00:00
|
|
|
}
|
2020-01-12 07:50:11 +00:00
|
|
|
if (err.message === REPOSITORY_ACCESS_FORBIDDEN) {
|
2021-11-08 19:20:03 +00:00
|
|
|
delete config.branchList;
|
2018-02-05 21:23:50 +00:00
|
|
|
logger.info('Repository is forbidden');
|
|
|
|
return err.message;
|
2018-07-09 09:28:33 +00:00
|
|
|
}
|
2020-01-12 07:50:11 +00:00
|
|
|
if (err.message === REPOSITORY_NOT_FOUND) {
|
2021-11-08 19:20:03 +00:00
|
|
|
delete config.branchList;
|
2018-03-09 10:50:04 +00:00
|
|
|
logger.error('Repository is not found');
|
2017-12-31 19:47:46 +00:00
|
|
|
return err.message;
|
2018-07-09 09:28:33 +00:00
|
|
|
}
|
2020-01-12 07:50:11 +00:00
|
|
|
if (err.message === REPOSITORY_FORKED) {
|
2017-11-05 04:45:49 +00:00
|
|
|
logger.info('Repository is a fork and not manually configured - skipping');
|
|
|
|
return err.message;
|
2018-07-09 09:28:33 +00:00
|
|
|
}
|
2020-01-12 07:50:11 +00:00
|
|
|
if (err.message === REPOSITORY_CANNOT_FORK) {
|
2018-10-08 08:41:55 +00:00
|
|
|
logger.info('Cannot fork repository - skipping');
|
|
|
|
return err.message;
|
|
|
|
}
|
2021-02-11 12:32:29 +00:00
|
|
|
if (err.message === REPOSITORY_NO_PACKAGE_FILES) {
|
2017-11-05 04:45:49 +00:00
|
|
|
logger.info('Repository has no package files - skipping');
|
|
|
|
return err.message;
|
2018-07-09 09:28:33 +00:00
|
|
|
}
|
2021-02-11 12:32:29 +00:00
|
|
|
if (err.message === NO_VULNERABILITY_ALERTS) {
|
2018-07-29 06:43:53 +00:00
|
|
|
logger.info('Repository has no vulnerability alerts - skipping');
|
|
|
|
return err.message;
|
|
|
|
}
|
2020-01-12 07:50:11 +00:00
|
|
|
if (err.message === REPOSITORY_CHANGED) {
|
2018-02-09 07:27:24 +00:00
|
|
|
logger.info('Repository has changed during renovation - aborting');
|
2021-11-08 19:20:03 +00:00
|
|
|
delete config.branchList;
|
2018-02-03 14:45:43 +00:00
|
|
|
return err.message;
|
2018-07-09 09:28:33 +00:00
|
|
|
}
|
2020-01-12 07:50:11 +00:00
|
|
|
if (err.message === CONFIG_VALIDATION) {
|
2021-11-08 19:20:03 +00:00
|
|
|
delete config.branchList;
|
2017-12-18 08:39:52 +00:00
|
|
|
logger.info({ error: err }, 'Repository has invalid config');
|
|
|
|
await raiseConfigWarningIssue(config, err);
|
|
|
|
return err.message;
|
2018-07-09 09:28:33 +00:00
|
|
|
}
|
2020-07-03 14:52:16 +00:00
|
|
|
if (err.message === CONFIG_SECRETS_EXPOSED) {
|
2021-11-08 19:20:03 +00:00
|
|
|
delete config.branchList;
|
2020-07-03 14:52:16 +00:00
|
|
|
logger.warn(
|
|
|
|
{ error: err },
|
|
|
|
'Repository aborted due to potential secrets exposure'
|
|
|
|
);
|
|
|
|
return err.message;
|
|
|
|
}
|
2020-06-22 19:28:02 +00:00
|
|
|
if (err instanceof ExternalHostError) {
|
2020-02-14 08:19:45 +00:00
|
|
|
logger.warn(
|
2022-03-03 15:08:43 +00:00
|
|
|
{ hostType: err.hostType, packageName: err.packageName, err: err.err },
|
2020-06-22 19:28:02 +00:00
|
|
|
'Host error'
|
2020-02-14 08:19:45 +00:00
|
|
|
);
|
2020-06-22 19:28:02 +00:00
|
|
|
logger.info('External host error causing abort - skipping');
|
2021-11-08 19:20:03 +00:00
|
|
|
delete config.branchList;
|
2018-01-14 17:58:49 +00:00
|
|
|
return err.message;
|
2018-07-09 09:28:33 +00:00
|
|
|
}
|
2019-07-02 05:28:45 +00:00
|
|
|
if (
|
|
|
|
err.message.includes('No space left on device') ||
|
2020-01-12 07:50:11 +00:00
|
|
|
err.message === SYSTEM_INSUFFICIENT_DISK_SPACE
|
2019-07-02 05:28:45 +00:00
|
|
|
) {
|
2018-09-08 05:16:05 +00:00
|
|
|
logger.error('Disk space error - skipping');
|
2021-11-08 19:20:03 +00:00
|
|
|
delete config.branchList;
|
2018-09-08 05:16:05 +00:00
|
|
|
return err.message;
|
|
|
|
}
|
2020-01-12 07:50:11 +00:00
|
|
|
if (err.message === PLATFORM_RATE_LIMIT_EXCEEDED) {
|
2018-03-22 08:26:20 +00:00
|
|
|
logger.warn('Rate limit exceeded - aborting');
|
2021-11-08 19:20:03 +00:00
|
|
|
delete config.branchList;
|
2020-04-16 16:08:53 +00:00
|
|
|
return err.message;
|
|
|
|
}
|
|
|
|
if (err.message === SYSTEM_INSUFFICIENT_MEMORY) {
|
|
|
|
logger.warn('Insufficient memory - aborting');
|
2021-11-08 19:20:03 +00:00
|
|
|
delete config.branchList;
|
2018-03-22 08:26:20 +00:00
|
|
|
return err.message;
|
2019-02-13 21:33:58 +00:00
|
|
|
}
|
2020-01-12 07:50:11 +00:00
|
|
|
if (err.message === PLATFORM_BAD_CREDENTIALS) {
|
2019-02-13 21:33:58 +00:00
|
|
|
logger.warn('Bad credentials - aborting');
|
2021-11-08 19:20:03 +00:00
|
|
|
delete config.branchList;
|
2019-02-13 21:33:58 +00:00
|
|
|
return err.message;
|
2018-07-09 09:28:33 +00:00
|
|
|
}
|
2020-01-12 07:50:11 +00:00
|
|
|
if (err.message === PLATFORM_INTEGRATION_UNAUTHORIZED) {
|
2018-12-03 11:03:46 +00:00
|
|
|
logger.warn('Integration unauthorized - aborting');
|
2021-11-08 19:20:03 +00:00
|
|
|
delete config.branchList;
|
2018-12-03 11:03:46 +00:00
|
|
|
return err.message;
|
|
|
|
}
|
2020-01-12 07:50:11 +00:00
|
|
|
if (err.message === PLATFORM_AUTHENTICATION_ERROR) {
|
2019-02-02 01:46:32 +00:00
|
|
|
logger.warn('Authentication error - aborting');
|
2021-11-08 19:20:03 +00:00
|
|
|
delete config.branchList;
|
2019-02-02 01:46:32 +00:00
|
|
|
return err.message;
|
|
|
|
}
|
2021-02-11 12:32:29 +00:00
|
|
|
if (err.message === TEMPORARY_ERROR) {
|
2019-03-16 06:55:39 +00:00
|
|
|
logger.info('Temporary error - aborting');
|
2021-11-08 19:20:03 +00:00
|
|
|
delete config.branchList;
|
2019-03-16 06:55:39 +00:00
|
|
|
return err.message;
|
|
|
|
}
|
2020-01-12 07:50:11 +00:00
|
|
|
if (err.message === MANAGER_LOCKFILE_ERROR) {
|
2021-11-08 19:20:03 +00:00
|
|
|
delete config.branchList;
|
2018-07-14 05:50:37 +00:00
|
|
|
logger.info('Lock file error - aborting');
|
2021-11-08 19:20:03 +00:00
|
|
|
delete config.branchList;
|
2018-05-24 14:28:36 +00:00
|
|
|
return err.message;
|
2017-11-05 04:45:49 +00:00
|
|
|
}
|
2019-06-12 09:44:29 +00:00
|
|
|
if (err.message.includes('The requested URL returned error: 5')) {
|
2019-06-12 14:14:44 +00:00
|
|
|
logger.warn({ err }, 'Git error - aborting');
|
2021-11-08 19:20:03 +00:00
|
|
|
delete config.branchList;
|
2019-06-12 14:14:44 +00:00
|
|
|
// rewrite this error
|
2020-06-22 19:28:02 +00:00
|
|
|
return EXTERNAL_HOST_ERROR;
|
2019-06-12 14:14:44 +00:00
|
|
|
}
|
|
|
|
if (
|
2020-07-23 10:43:06 +00:00
|
|
|
err.message.includes('remote end hung up unexpectedly') ||
|
2019-06-12 14:14:44 +00:00
|
|
|
err.message.includes('access denied or repository not exported')
|
|
|
|
) {
|
|
|
|
logger.warn({ err }, 'Git error - aborting');
|
2021-11-08 19:20:03 +00:00
|
|
|
delete config.branchList;
|
2019-06-12 08:49:21 +00:00
|
|
|
// rewrite this error
|
2020-06-22 19:28:02 +00:00
|
|
|
return EXTERNAL_HOST_ERROR;
|
2019-06-12 08:49:21 +00:00
|
|
|
}
|
2020-10-12 08:36:49 +00:00
|
|
|
if (err.message.includes('fatal: not a git repository')) {
|
2021-11-08 19:20:03 +00:00
|
|
|
delete config.branchList;
|
2021-02-11 12:32:29 +00:00
|
|
|
return TEMPORARY_ERROR;
|
2020-10-12 08:36:49 +00:00
|
|
|
}
|
2017-11-05 04:45:49 +00:00
|
|
|
// Swallow this error so that other repositories can be processed
|
2018-09-05 08:31:21 +00:00
|
|
|
logger.error({ err }, `Repository has unknown error`);
|
2017-11-05 04:45:49 +00:00
|
|
|
// delete branchList to avoid cleaning up branches
|
2021-11-08 19:20:03 +00:00
|
|
|
delete config.branchList;
|
|
|
|
|
2020-01-12 07:50:11 +00:00
|
|
|
return UNKNOWN_ERROR;
|
2017-11-05 04:45:49 +00:00
|
|
|
}
|