diff --git a/lib/config/presets/bitbucket-server/index.spec.ts b/lib/config/presets/bitbucket-server/index.spec.ts index afa5e7022af186368e047097e89998c55c3695f8..443d9643741b0210699e5c458f5150af033d94c9 100644 --- a/lib/config/presets/bitbucket-server/index.spec.ts +++ b/lib/config/presets/bitbucket-server/index.spec.ts @@ -1,7 +1,7 @@ import * as httpMock from '../../../../test/http-mock'; import { getName, mocked } from '../../../../test/util'; import * as _hostRules from '../../../util/host-rules'; -import { PRESET_DEP_NOT_FOUND } from '../util'; +import { PRESET_DEP_NOT_FOUND, PRESET_INVALID_JSON } from '../util'; import * as bitbucketServer from '.'; jest.mock('../../../util/host-rules'); @@ -73,7 +73,7 @@ describe(getName(__filename), () => { 'some-filename.json', bitbucketApiHost ) - ).rejects.toThrow('invalid preset JSON'); + ).rejects.toThrow(PRESET_INVALID_JSON); expect(httpMock.getTrace()).toMatchSnapshot(); }); @@ -93,7 +93,7 @@ describe(getName(__filename), () => { 'some-filename.json', bitbucketApiHost ) - ).rejects.toThrow('invalid preset JSON'); + ).rejects.toThrow(PRESET_INVALID_JSON); expect(httpMock.getTrace()).toMatchSnapshot(); }); }); diff --git a/lib/config/presets/bitbucket-server/index.ts b/lib/config/presets/bitbucket-server/index.ts index 727d8246da80d6fefe177b440cddedc6538492a2..3dbe80cf46caaaf894664804789df86a4f08ace9 100644 --- a/lib/config/presets/bitbucket-server/index.ts +++ b/lib/config/presets/bitbucket-server/index.ts @@ -6,7 +6,11 @@ import { setBaseUrl, } from '../../../util/http/bitbucket-server'; import type { Preset } from '../types'; -import { PRESET_DEP_NOT_FOUND, fetchPreset } from '../util'; +import { + PRESET_DEP_NOT_FOUND, + PRESET_INVALID_JSON, + fetchPreset, +} from '../util'; const http = new BitbucketServerHttp(); @@ -34,14 +38,14 @@ export async function fetchJSONFile( } if (!res.body.isLastPage) { logger.warn({ size: res.body.size }, 'Renovate config to big'); - throw new Error('invalid preset JSON'); + throw new Error(PRESET_INVALID_JSON); } try { const content = res.body.lines.map((l) => l.text).join(''); const parsed = JSON.parse(content); return parsed; } catch (err) { - throw new Error('invalid preset JSON'); + throw new Error(PRESET_INVALID_JSON); } } diff --git a/lib/config/presets/gitea/index.spec.ts b/lib/config/presets/gitea/index.spec.ts index ddab9e13ab2096b24b24132da4d1723986bb1f9b..79baf2260ea97a1d4577c748e0f50579ce4e97c0 100644 --- a/lib/config/presets/gitea/index.spec.ts +++ b/lib/config/presets/gitea/index.spec.ts @@ -2,7 +2,7 @@ import * as httpMock from '../../../../test/http-mock'; import { getName, mocked } from '../../../../test/util'; import * as _hostRules from '../../../util/host-rules'; import { setBaseUrl } from '../../../util/http/gitea'; -import { PRESET_NOT_FOUND } from '../util'; +import { PRESET_INVALID_JSON, PRESET_NOT_FOUND } from '../util'; import * as gitea from '.'; jest.mock('../../../util/host-rules'); @@ -63,7 +63,7 @@ describe(getName(__filename), () => { await expect( gitea.getPreset({ packageName: 'some/repo' }) - ).rejects.toThrow('invalid preset JSON'); + ).rejects.toThrow(PRESET_INVALID_JSON); expect(httpMock.getTrace()).toMatchSnapshot(); }); @@ -77,7 +77,7 @@ describe(getName(__filename), () => { await expect( gitea.getPreset({ packageName: 'some/repo' }) - ).rejects.toThrow('invalid preset JSON'); + ).rejects.toThrow(PRESET_INVALID_JSON); expect(httpMock.getTrace()).toMatchSnapshot(); }); diff --git a/lib/config/presets/gitea/index.ts b/lib/config/presets/gitea/index.ts index ae3229b7213f3dc0582360f5c9bb5670f6fe7830..3c4f560bb2cbd452115f480273cf4326ec475ac3 100644 --- a/lib/config/presets/gitea/index.ts +++ b/lib/config/presets/gitea/index.ts @@ -5,7 +5,11 @@ import { } from '../../../platform/gitea/gitea-helper'; import { ExternalHostError } from '../../../types/errors/external-host-error'; import type { Preset, PresetConfig } from '../types'; -import { PRESET_DEP_NOT_FOUND, fetchPreset } from '../util'; +import { + PRESET_DEP_NOT_FOUND, + PRESET_INVALID_JSON, + fetchPreset, +} from '../util'; export const Endpoint = 'https://gitea.com/api/v1/'; @@ -33,7 +37,7 @@ export async function fetchJSONFile( const parsed = JSON.parse(content); return parsed; } catch (err) { - throw new Error('invalid preset JSON'); + throw new Error(PRESET_INVALID_JSON); } } diff --git a/lib/config/presets/github/index.spec.ts b/lib/config/presets/github/index.spec.ts index 6de3ecc7b9df1f6058a45dc41f7bb9c51cab9c4f..fe95e80d6f1bb8a0a9d12012cdb627d2b74d76fc 100644 --- a/lib/config/presets/github/index.spec.ts +++ b/lib/config/presets/github/index.spec.ts @@ -1,7 +1,7 @@ import * as httpMock from '../../../../test/http-mock'; import { getName, mocked } from '../../../../test/util'; import * as _hostRules from '../../../util/host-rules'; -import { PRESET_NOT_FOUND } from '../util'; +import { PRESET_INVALID_JSON, PRESET_NOT_FOUND } from '../util'; import * as github from '.'; jest.mock('../../../util/host-rules'); @@ -61,7 +61,7 @@ describe(getName(__filename), () => { await expect( github.getPreset({ packageName: 'some/repo' }) - ).rejects.toThrow('invalid preset JSON'); + ).rejects.toThrow(PRESET_INVALID_JSON); expect(httpMock.getTrace()).toMatchSnapshot(); }); @@ -75,7 +75,7 @@ describe(getName(__filename), () => { await expect( github.getPreset({ packageName: 'some/repo' }) - ).rejects.toThrow('invalid preset JSON'); + ).rejects.toThrow(PRESET_INVALID_JSON); expect(httpMock.getTrace()).toMatchSnapshot(); }); diff --git a/lib/config/presets/github/index.ts b/lib/config/presets/github/index.ts index fef6d0f12423778f87d0bde7ec61aadb93d62b50..0f1a9be5cb0d094b55dfee4ca74bb83b82da6a6a 100644 --- a/lib/config/presets/github/index.ts +++ b/lib/config/presets/github/index.ts @@ -2,7 +2,11 @@ import { logger } from '../../../logger'; import { ExternalHostError } from '../../../types/errors/external-host-error'; import { GithubHttp } from '../../../util/http/github'; import type { Preset, PresetConfig } from '../types'; -import { PRESET_DEP_NOT_FOUND, fetchPreset } from '../util'; +import { + PRESET_DEP_NOT_FOUND, + PRESET_INVALID_JSON, + fetchPreset, +} from '../util'; export const Endpoint = 'https://api.github.com/'; @@ -33,7 +37,7 @@ export async function fetchJSONFile( const parsed = JSON.parse(content); return parsed; } catch (err) { - throw new Error('invalid preset JSON'); + throw new Error(PRESET_INVALID_JSON); } } diff --git a/lib/config/presets/util.ts b/lib/config/presets/util.ts index 12c0e88576dd126999fb744848ddc7979229945d..acbaad5bd8413b92bd31aabf3e44a7bb23fb218e 100644 --- a/lib/config/presets/util.ts +++ b/lib/config/presets/util.ts @@ -4,6 +4,7 @@ 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_JSON = 'invalid preset JSON'; export type PresetFetcher = ( repo: string,