Skip to content

Commit

Permalink
fix(rubygems): Don't throw on metadata errors (#23224)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Jul 6, 2023
1 parent e1ab6a7 commit 369d927
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
13 changes: 9 additions & 4 deletions lib/modules/datasource/rubygems/metadata-cache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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' }],
});
});
});
12 changes: 5 additions & 7 deletions lib/modules/datasource/rubygems/metadata-cache.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 };
}
}
}

0 comments on commit 369d927

Please sign in to comment.