diff --git a/lib/config/presets/index.spec.ts b/lib/config/presets/index.spec.ts index 69d1d79f050bfae9181e88760f2ad0d8b4b87942..fa6e3f42dbb0ca00c5d9f4227d3285a3e2f8e20a 100644 --- a/lib/config/presets/index.spec.ts +++ b/lib/config/presets/index.spec.ts @@ -4,6 +4,7 @@ import * as _local from './local'; import * as _npm from './npm'; import { PRESET_DEP_NOT_FOUND, + PRESET_INVALID_JSON, PRESET_NOT_FOUND, PRESET_RENOVATE_CONFIG_NOT_FOUND, } from './util'; @@ -115,6 +116,22 @@ describe('config/presets/index', () => { expect(e.validationMessage).toBeUndefined(); }); + it('throws if invalid preset json', async () => { + config.foo = 1; + config.extends = ['org/repo']; + let e: Error; + local.getPreset.mockRejectedValueOnce(new Error(PRESET_INVALID_JSON)); + try { + await presets.resolveConfigPresets(config); + } catch (err) { + e = err; + } + expect(e).toBeDefined(); + expect(e.validationSource).toBeUndefined(); + expect(e.validationError).toBe('Preset is invalid JSON (org/repo)'); + expect(e.validationMessage).toBeUndefined(); + }); + it('throws noconfig', async () => { config.foo = 1; config.extends = ['noconfig:base']; @@ -143,7 +160,9 @@ describe('config/presets/index', () => { } expect(e).toBeDefined(); expect(e.validationSource).toBeUndefined(); - expect(e.validationError).toBeUndefined(); + expect(e.validationError).toBe( + 'Preset caused unexpected error (throw:base)' + ); expect(e.validationMessage).toBeUndefined(); }); diff --git a/lib/config/presets/index.ts b/lib/config/presets/index.ts index fa136183e9b9f80d652a60f48b2455f372833d5a..f926a19957ce9b20283a325e8d9d0d8dff42a261 100644 --- a/lib/config/presets/index.ts +++ b/lib/config/presets/index.ts @@ -22,6 +22,7 @@ import type { ParsedPreset, PresetApi } from './types'; import { PRESET_DEP_NOT_FOUND, PRESET_INVALID, + PRESET_INVALID_JSON, PRESET_NOT_FOUND, PRESET_PROHIBITED_SUBPRESET, PRESET_RENOVATE_CONFIG_NOT_FOUND, @@ -293,6 +294,10 @@ export async function resolveConfigPresets( error.validationError = `Preset is invalid (${preset})`; } else if (err.message === PRESET_PROHIBITED_SUBPRESET) { error.validationError = `Sub-presets cannot be combined with a custom path (${preset})`; + } else if (err.message === PRESET_INVALID_JSON) { + error.validationError = `Preset is invalid JSON (${preset})`; + } else { + error.validationError = `Preset caused unexpected error (${preset})`; } // istanbul ignore if if (existingPresets.length) {