fix(maven): Catch and log URL construction errors (#4572)

This commit is contained in:
Sergio Zharinov 2019-10-03 00:26:45 +04:00 committed by Rhys Arkins
parent ecdb9b3c3b
commit e67523e152
2 changed files with 22 additions and 5 deletions

View file

@ -91,10 +91,19 @@ async function downloadMavenXml(
repoUrl: string,
dependencyFilePath: string
): Promise<XmlDocument | null> {
const pkgUrl = new url.URL(
`${dependency.dependencyUrl}/${dependencyFilePath}`,
repoUrl
);
let pkgUrl;
try {
pkgUrl = new url.URL(
`${dependency.dependencyUrl}/${dependencyFilePath}`,
repoUrl
);
} catch (err) {
logger.debug(
{ err, dependency, repoUrl, dependencyFilePath },
`Error constructing URL for ${dependency.display}`
);
return null;
}
let rawContent: string;
switch (pkgUrl.protocol) {

View file

@ -215,7 +215,15 @@ describe('datasource/maven', () => {
});
expect(releases).toBeNull();
});
it('should return null for invalid registryUrls', async () => {
const releases = await datasource.getPkgReleases({
...config,
lookupName: 'mysql:mysql-connector-java',
// eslint-disable-next-line no-template-curly-in-string
registryUrls: ['${project.baseUri}../../repository/'],
});
expect(releases).toBeNull();
});
it('should support scm.url values prefixed with "scm:"', async () => {
const releases = await datasource.getPkgReleases({
...config,