diff --git a/lib/modules/datasource/custom/index.spec.ts b/lib/modules/datasource/custom/index.spec.ts index 2d997c6b30eaaba0880e000a26fc4fa59d9f1dc9..2eb0f46212fa2270cc1efcfc4a23d83eb04a2f05 100644 --- a/lib/modules/datasource/custom/index.spec.ts +++ b/lib/modules/datasource/custom/index.spec.ts @@ -3,6 +3,7 @@ import { getPkgReleases } from '..'; import { Fixtures } from '../../../../test/fixtures'; import * as httpMock from '../../../../test/http-mock'; import { fs } from '../../../../test/util'; +import { logger } from '../../../logger'; import { CustomDatasource } from './index'; jest.mock('../../../util/fs'); @@ -228,6 +229,31 @@ describe('modules/datasource/custom/index', () => { expect(result).toEqual(expected); }); + it('returns null if transformation using jsonata rules fail', async () => { + httpMock + .scope('https://example.com') + .get('/v1') + .reply(200, '1.0.0 \n2.0.0 \n 3.0.0 ', { + 'Content-Type': 'text/plain', + }); + const result = await getPkgReleases({ + datasource: `${CustomDatasource.id}.foo`, + packageName: 'myPackage', + customDatasources: { + foo: { + defaultRegistryUrlTemplate: 'https://example.com/v1', + transformTemplates: ['$[.name = "Alice" and'], + format: 'plain', + }, + }, + }); + expect(result).toBeNull(); + expect(logger.debug).toHaveBeenCalledWith( + { err: expect.any(Object), transformTemplate: '$[.name = "Alice" and' }, + 'Error while transforming response', + ); + }); + it('return releases for plain text API when only returns a single version', async () => { const expected = { releases: [ diff --git a/lib/modules/datasource/custom/index.ts b/lib/modules/datasource/custom/index.ts index d230e14179119238b9bb0c2c8a0e974bbf6cbe1c..0ecdc11bc8547cb54df3f5ad7e31842dd2b6059b 100644 --- a/lib/modules/datasource/custom/index.ts +++ b/lib/modules/datasource/custom/index.ts @@ -46,8 +46,16 @@ export class CustomDatasource extends Datasource { logger.trace({ data }, `Custom manager fetcher '${format}' returned data.`); for (const transformTemplate of transformTemplates) { - const expression = jsonata(transformTemplate); - data = await expression.evaluate(data); + try { + const expression = jsonata(transformTemplate); + data = await expression.evaluate(data); + } catch (err) { + logger.debug( + { err, transformTemplate }, + 'Error while transforming response', + ); + return null; + } } try {