diff --git a/lib/config/presets/index.spec.ts b/lib/config/presets/index.spec.ts index 4b829c7ed6d8a4137b50dc3041f5f96848a015b6..5600d77e797383d1eec7ee52d4690ee2a4f0f6a8 100644 --- a/lib/config/presets/index.spec.ts +++ b/lib/config/presets/index.spec.ts @@ -3,6 +3,11 @@ import { getName, mocked } from '../../../test/util'; import presetIkatyang from './__fixtures__/renovate-config-ikatyang.json'; import * as _local from './local'; import * as _npm from './npm'; +import { + PRESET_DEP_NOT_FOUND, + PRESET_NOT_FOUND, + PRESET_RENOVATE_CONFIG_NOT_FOUND, +} from './util'; import * as presets from '.'; jest.mock('./npm'); @@ -19,16 +24,16 @@ npm.getPreset = jest.fn(({ packageName, presetName }) => { ][presetName]; } if (packageName === 'renovate-config-notfound') { - throw new Error('dep not found'); + throw new Error(PRESET_DEP_NOT_FOUND); } if (packageName === 'renovate-config-noconfig') { - throw new Error('preset renovate-config not found'); + throw new Error(PRESET_RENOVATE_CONFIG_NOT_FOUND); } if (packageName === 'renovate-config-throw') { throw new Error('whoops'); } if (packageName === 'renovate-config-wrongpreset') { - throw new Error('preset not found'); + throw new Error(PRESET_NOT_FOUND); } return null; }); diff --git a/lib/config/presets/index.ts b/lib/config/presets/index.ts index b3453affb237d66e412b93678bb340279c9f599c..f534e26939864ea9e2bf1d572c0c84a0a72d4dc8 100644 --- a/lib/config/presets/index.ts +++ b/lib/config/presets/index.ts @@ -17,7 +17,13 @@ import * as internal from './internal'; import * as local from './local'; import * as npm from './npm'; import type { PresetApi } from './types'; -import { PRESET_DEP_NOT_FOUND } from './util'; +import { + PRESET_DEP_NOT_FOUND, + PRESET_INVALID, + PRESET_NOT_FOUND, + PRESET_PROHIBITED_SUBPRESET, + PRESET_RENOVATE_CONFIG_NOT_FOUND, +} from './util'; const presetSources: Record<string, PresetApi> = { github, @@ -134,10 +140,10 @@ export function parsePreset(input: string): ParsedPreset { // Validation if (str.includes(':')) { - throw new Error('prohibited sub-preset'); + throw new Error(PRESET_PROHIBITED_SUBPRESET); } if (!re.test(str)) { - throw new Error('invalid preset'); + throw new Error(PRESET_INVALID); } [, packageName, presetPath, presetName] = re.exec(str); } else { @@ -255,13 +261,13 @@ export async function resolveConfigPresets( const error = new Error(CONFIG_VALIDATION); if (err.message === PRESET_DEP_NOT_FOUND) { error.validationError = `Cannot find preset's package (${preset})`; - } else if (err.message === 'preset renovate-config not found') { + } else if (err.message === PRESET_RENOVATE_CONFIG_NOT_FOUND) { error.validationError = `Preset package is missing a renovate-config entry (${preset})`; - } else if (err.message === 'preset not found') { + } else if (err.message === PRESET_NOT_FOUND) { error.validationError = `Preset name not found within published preset config (${preset})`; - } else if (err.message === 'invalid preset') { + } else if (err.message === PRESET_INVALID) { error.validationError = `Preset is invalid (${preset})`; - } else if (err.message === 'prohibited sub-preset') { + } else if (err.message === PRESET_PROHIBITED_SUBPRESET) { error.validationError = `Sub-presets cannot be combined with a custom path (${preset})`; } // istanbul ignore if diff --git a/lib/config/presets/npm/index.ts b/lib/config/presets/npm/index.ts index feefeb73428826998d70c3b503fab00f4eac0d3e..e3e51c507d9f18010edd0f933421c2bb1c85c190 100644 --- a/lib/config/presets/npm/index.ts +++ b/lib/config/presets/npm/index.ts @@ -3,6 +3,11 @@ import { NpmResponse } from '../../../datasource/npm/types'; import { logger } from '../../../logger'; import { Http } from '../../../util/http'; import type { Preset, PresetConfig } from '../types'; +import { + PRESET_DEP_NOT_FOUND, + PRESET_NOT_FOUND, + PRESET_RENOVATE_CONFIG_NOT_FOUND, +} from '../util'; const id = 'npm'; @@ -19,10 +24,10 @@ export async function getPreset({ .body; dep = body.versions[body['dist-tags'].latest]; } catch (err) { - throw new Error('dep not found'); + throw new Error(PRESET_DEP_NOT_FOUND); } if (!dep['renovate-config']) { - throw new Error('preset renovate-config not found'); + throw new Error(PRESET_RENOVATE_CONFIG_NOT_FOUND); } const presetConfig = dep['renovate-config'][presetName]; if (!presetConfig) { @@ -31,7 +36,7 @@ export async function getPreset({ { presetNames, presetName }, 'Preset not found within renovate-config' ); - throw new Error('preset not found'); + throw new Error(PRESET_NOT_FOUND); } return presetConfig; } diff --git a/lib/config/presets/util.ts b/lib/config/presets/util.ts index acbaad5bd8413b92bd31aabf3e44a7bb23fb218e..6d224a8c1552519be4d2d211abdb1a85fe7ef2ac 100644 --- a/lib/config/presets/util.ts +++ b/lib/config/presets/util.ts @@ -3,8 +3,12 @@ import { ensureTrailingSlash } from '../../util/url'; import type { Preset } from './types'; export const PRESET_DEP_NOT_FOUND = 'dep not found'; -export const PRESET_NOT_FOUND = 'preset not found'; +export const PRESET_INVALID = 'invalid preset'; export const PRESET_INVALID_JSON = 'invalid preset JSON'; +export const PRESET_NOT_FOUND = 'preset not found'; +export const PRESET_PROHIBITED_SUBPRESET = 'prohibited sub-preset'; +export const PRESET_RENOVATE_CONFIG_NOT_FOUND = + 'preset renovate-config not found'; export type PresetFetcher = ( repo: string,