From 369d9273efb6e9e332dcf9ea523f47811f781d65 Mon Sep 17 00:00:00 2001 From: Sergei Zharinov Date: Thu, 6 Jul 2023 21:45:42 +0300 Subject: [PATCH] fix(rubygems): Don't throw on metadata errors (#23224) --- .../datasource/rubygems/metadata-cache.spec.ts | 13 +++++++++---- lib/modules/datasource/rubygems/metadata-cache.ts | 12 +++++------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/modules/datasource/rubygems/metadata-cache.spec.ts b/lib/modules/datasource/rubygems/metadata-cache.spec.ts index c1bc38244755dc..ab7960f20306ea 100644 --- a/lib/modules/datasource/rubygems/metadata-cache.spec.ts +++ b/lib/modules/datasource/rubygems/metadata-cache.spec.ts @@ -192,7 +192,7 @@ describe('modules/datasource/rubygems/metadata-cache', () => { }); }); - it('throws on unknown error', async () => { + it('returns fallback result on unknown error', async () => { const cache = new MetadataCache(new Http('test')); httpMock @@ -201,9 +201,14 @@ describe('modules/datasource/rubygems/metadata-cache', () => { .reply(500); const versions = ['1', '2', '3']; + const res = await cache.getRelease( + 'https://rubygems.org', + 'foobar', + versions + ); - await expect( - cache.getRelease('https://rubygems.org', 'foobar', versions) - ).rejects.toThrow(); + expect(res).toEqual({ + releases: [{ version: '1' }, { version: '2' }, { version: '3' }], + }); }); }); diff --git a/lib/modules/datasource/rubygems/metadata-cache.ts b/lib/modules/datasource/rubygems/metadata-cache.ts index a5f1de6893ce96..3084ae6587cefe 100644 --- a/lib/modules/datasource/rubygems/metadata-cache.ts +++ b/lib/modules/datasource/rubygems/metadata-cache.ts @@ -1,6 +1,7 @@ import hasha from 'hasha'; +import { logger } from '../../../logger'; import * as packageCache from '../../../util/cache/package'; -import { Http, HttpError } from '../../../util/http'; +import type { Http } from '../../../util/http'; import { joinUrlParts } from '../../../util/url'; import type { ReleaseResult } from '../types'; import { GemMetadata, GemVersions } from './schema'; @@ -62,12 +63,9 @@ export class MetadataCache { ); return data; } catch (err) { - if (err instanceof HttpError && err.response?.statusCode === 404) { - const releases = versions.map((version) => ({ version })); - return { releases }; - } - - throw err; + logger.debug({ err }, 'Rubygems: failed to fetch metadata'); + const releases = versions.map((version) => ({ version })); + return { releases }; } } }