diff --git a/lib/datasource/cdnjs/index.ts b/lib/datasource/cdnjs/index.ts index a994a6b8c639e8294acb11c3075107f97d0ffc90..58f912c6454202f071a5bb16a3558e582630017c 100644 --- a/lib/datasource/cdnjs/index.ts +++ b/lib/datasource/cdnjs/index.ts @@ -1,4 +1,3 @@ -import { logger } from '../../logger'; import { ExternalHostError } from '../../types/errors/external-host-error'; import { Http } from '../../util/http'; import { CachePromise, cacheAble } from '../cache'; @@ -57,11 +56,9 @@ export async function getReleases({ } return result; } catch (err) { - if (err.statusCode === 404) { - logger.debug({ library }, 'cdnjs library not found'); - return null; + if (err.statusCode !== 404) { + throw new ExternalHostError(err); } - // Throw an ExternalHostError for all other types of errors - throw new ExternalHostError(err); + throw err; } } diff --git a/lib/datasource/crate/index.ts b/lib/datasource/crate/index.ts index 9715b4eab1835366fb1494a94b14e5267d0e9995..324dad6e0065f8731535a961e0de8d38e09fcd5b 100644 --- a/lib/datasource/crate/index.ts +++ b/lib/datasource/crate/index.ts @@ -1,4 +1,3 @@ -import { logger } from '../../logger'; import { ExternalHostError } from '../../types/errors/external-host-error'; import * as packageCache from '../../util/cache/package'; import { Http } from '../../util/http'; @@ -66,18 +65,12 @@ export async function getReleases({ await packageCache.set(cacheNamespace, cacheKey, result, cacheMinutes); return result; } catch (err) { - if (err.statusCode === 404 || err.code === 'ENOTFOUND') { - logger.debug({ lookupName }, `Dependency lookup failure: not found`); - logger.debug({ err }, 'Crate lookup error'); - return null; - } if ( err.statusCode === 429 || (err.statusCode >= 500 && err.statusCode < 600) ) { throw new ExternalHostError(err); } - logger.warn({ err, lookupName }, 'crates.io lookup failure: Unknown error'); - return null; + throw err; } } diff --git a/lib/datasource/dart/index.ts b/lib/datasource/dart/index.ts index 241394373b5d7b4bf1ced4a1d2e33d70cdac66de..94f6dc4d218ae097f7c97fcf810aeeec87819400 100644 --- a/lib/datasource/dart/index.ts +++ b/lib/datasource/dart/index.ts @@ -1,4 +1,3 @@ -import { logger } from '../../logger'; import { ExternalHostError } from '../../types/errors/external-host-error'; import { Http, HttpResponse } from '../../util/http'; import { GetReleasesConfig, ReleaseResult } from '../common'; @@ -25,22 +24,13 @@ export async function getReleases({ try { raw = await http.getJson<DartResult>(pkgUrl); } catch (err) { - if (err.statusCode === 404 || err.code === 'ENOTFOUND') { - logger.debug({ lookupName }, `Dependency lookup failure: not found`); - logger.debug({ err }, 'Dart lookup error'); - return null; - } if ( err.statusCode === 429 || (err.statusCode >= 500 && err.statusCode < 600) ) { throw new ExternalHostError(err); } - logger.warn( - { err, lookupName }, - 'pub.dartlang.org lookup failure: Unknown error' - ); - return null; + throw err; } const body = raw && raw.body; diff --git a/lib/datasource/docker/index.ts b/lib/datasource/docker/index.ts index 4af0da52eac34ecc8fbad39b810ab925e19e3531..bb7d57448347109be34a94ecc6ffa2099f97c9d9 100644 --- a/lib/datasource/docker/index.ts +++ b/lib/datasource/docker/index.ts @@ -417,25 +417,12 @@ async function getTags( if (err instanceof ExternalHostError) { throw err; } - logger.debug( - { - err, - }, - 'docker.getTags() error' - ); if (err.statusCode === 404 && !repository.includes('/')) { logger.debug( `Retrying Tags for ${registry}/${repository} using library/ prefix` ); return getTags(registry, 'library/' + repository); } - if (err.statusCode === 401 || err.statusCode === 403) { - logger.debug( - { registry, dockerRepository: repository, err }, - 'Not authorised to look up docker tags' - ); - return null; - } // prettier-ignore if (err.statusCode === 429 && registry.endsWith('docker.io')) { // lgtm [js/incomplete-url-substring-sanitization] logger.warn( @@ -451,18 +438,7 @@ async function getTags( ); throw new ExternalHostError(err); } - if (err.code === 'ETIMEDOUT') { - logger.debug( - { registry }, - 'Timeout when attempting to connect to docker registry' - ); - return null; - } - logger.warn( - { registry, dockerRepository: repository, err }, - 'Error getting docker image tags' - ); - return null; + throw err; } } diff --git a/lib/datasource/galaxy/index.ts b/lib/datasource/galaxy/index.ts index ed01e05fe8a44251b1f6572c2844271e8a4b4374..48ef50b7c782dfc930ca84ee3fcd37a2ec9dd3f0 100644 --- a/lib/datasource/galaxy/index.ts +++ b/lib/datasource/galaxy/index.ts @@ -99,6 +99,6 @@ export async function getReleases({ ) { throw new ExternalHostError(err); } - return null; + throw err; } } diff --git a/lib/datasource/git-refs/index.ts b/lib/datasource/git-refs/index.ts index 50820ee59209506b5d614d199acfa4c55ae5be99..c872bc33f23336b5a4a19105cd30eac4f7ed17a5 100644 --- a/lib/datasource/git-refs/index.ts +++ b/lib/datasource/git-refs/index.ts @@ -1,5 +1,4 @@ import simpleGit from 'simple-git/promise'; -import { logger } from '../../logger'; import * as packageCache from '../../util/cache/package'; import * as semver from '../../versioning/semver'; import { DigestConfig, GetReleasesConfig, ReleaseResult } from '../common'; @@ -21,90 +20,80 @@ export async function getRawRefs({ lookupName, }: GetReleasesConfig): Promise<RawRefs[] | null> { const git = simpleGit(); - try { - const cacheNamespace = 'git-raw-refs'; - - const cachedResult = await packageCache.get<RawRefs[]>( - cacheNamespace, - lookupName - ); - /* istanbul ignore next line */ - if (cachedResult) { - return cachedResult; - } - - // fetch remote tags - const lsRemote = await git.listRemote([lookupName]); - if (!lsRemote) { - return null; - } - - const refMatch = /(?<hash>.*?)\s+refs\/(?<type>.*?)\/(?<value>.*)/; - const headMatch = /(?<hash>.*?)\s+HEAD/; - - const refs = lsRemote - .trim() - .split('\n') - .map((line) => line.trim()) - .map((line) => { - let match = refMatch.exec(line); - if (match) { - return { - type: match.groups.type, - value: match.groups.value, - hash: match.groups.hash, - }; - } - match = headMatch.exec(line); - if (match) { - return { - type: '', - value: 'HEAD', - hash: match.groups.hash, - }; - } - // istanbul ignore next - return null; - }) - .filter(Boolean) - .filter((ref) => ref.type !== 'pull' && !ref.value.endsWith('^{}')); - await packageCache.set(cacheNamespace, lookupName, refs, cacheMinutes); - return refs; - } catch (err) { - logger.info({ err }, `Git-Raw-Refs lookup error in ${lookupName}`); + const cacheNamespace = 'git-raw-refs'; + + const cachedResult = await packageCache.get<RawRefs[]>( + cacheNamespace, + lookupName + ); + /* istanbul ignore next line */ + if (cachedResult) { + return cachedResult; } - return null; + + // fetch remote tags + const lsRemote = await git.listRemote([lookupName]); + if (!lsRemote) { + return null; + } + + const refMatch = /(?<hash>.*?)\s+refs\/(?<type>.*?)\/(?<value>.*)/; + const headMatch = /(?<hash>.*?)\s+HEAD/; + + const refs = lsRemote + .trim() + .split('\n') + .map((line) => line.trim()) + .map((line) => { + let match = refMatch.exec(line); + if (match) { + return { + type: match.groups.type, + value: match.groups.value, + hash: match.groups.hash, + }; + } + match = headMatch.exec(line); + if (match) { + return { + type: '', + value: 'HEAD', + hash: match.groups.hash, + }; + } + // istanbul ignore next + return null; + }) + .filter(Boolean) + .filter((ref) => ref.type !== 'pull' && !ref.value.endsWith('^{}')); + await packageCache.set(cacheNamespace, lookupName, refs, cacheMinutes); + return refs; } export async function getReleases({ lookupName, }: GetReleasesConfig): Promise<ReleaseResult | null> { - try { - const rawRefs: RawRefs[] = await getRawRefs({ lookupName }); - - const refs = rawRefs - .filter((ref) => ref.type === 'tags' || ref.type === 'heads') - .map((ref) => ref.value) - .filter((ref) => semver.isVersion(ref)); - - const uniqueRefs = [...new Set(refs)]; - - const sourceUrl = lookupName.replace(/\.git$/, '').replace(/\/$/, ''); - - const result: ReleaseResult = { - sourceUrl, - releases: uniqueRefs.map((ref) => ({ - version: ref, - gitRef: ref, - newDigest: rawRefs.find((rawRef) => rawRef.value === ref).hash, - })), - }; - - return result; - } catch (err) { - logger.error({ err }, `Git-Refs lookup error in ${lookupName}`); - } - return null; + const rawRefs: RawRefs[] = await getRawRefs({ lookupName }); + + const refs = rawRefs + .filter((ref) => ref.type === 'tags' || ref.type === 'heads') + .map((ref) => ref.value) + .filter((ref) => semver.isVersion(ref)); + + const uniqueRefs = [...new Set(refs)]; + + const sourceUrl = lookupName.replace(/\.git$/, '').replace(/\/$/, ''); + + const result: ReleaseResult = { + sourceUrl, + releases: uniqueRefs.map((ref) => ({ + version: ref, + gitRef: ref, + newDigest: rawRefs.find((rawRef) => rawRef.value === ref).hash, + })), + }; + + return result; } export async function getDigest( diff --git a/lib/datasource/git-submodules/index.ts b/lib/datasource/git-submodules/index.ts index 4a812a3fb748f941b8e850ea981b8ba018773e6b..22a8b6adeab01338ccc981ca920735cb3eb4be5a 100644 --- a/lib/datasource/git-submodules/index.ts +++ b/lib/datasource/git-submodules/index.ts @@ -1,7 +1,6 @@ import { URL } from 'url'; import Git from 'simple-git/promise'; -import { logger } from '../../logger'; import * as packageCache from '../../util/cache/package'; import { DigestConfig, GetReleasesConfig, ReleaseResult } from '../common'; @@ -23,31 +22,26 @@ export async function getReleases({ } const git = Git(); - try { - const newHash = ( - await git.listRemote(['--refs', registryUrls[0], registryUrls[1]]) - ) - .trim() - .split(/\t/)[0]; + const newHash = ( + await git.listRemote(['--refs', registryUrls[0], registryUrls[1]]) + ) + .trim() + .split(/\t/)[0]; - const sourceUrl = new URL(registryUrls[0]); - sourceUrl.username = ''; + const sourceUrl = new URL(registryUrls[0]); + sourceUrl.username = ''; - const result = { - sourceUrl: sourceUrl.href, - releases: [ - { - version: newHash, - }, - ], - }; - const cacheMinutes = 60; - await packageCache.set(cacheNamespace, cacheKey, result, cacheMinutes); - return result; - } catch (err) { - logger.debug({ err }, `Git-SubModules lookup error in ${lookupName}`); - } - return null; + const result = { + sourceUrl: sourceUrl.href, + releases: [ + { + version: newHash, + }, + ], + }; + const cacheMinutes = 60; + await packageCache.set(cacheNamespace, cacheKey, result, cacheMinutes); + return result; } export const getDigest = ( diff --git a/lib/datasource/github-releases/index.ts b/lib/datasource/github-releases/index.ts index 438f6509ac5f6aaee85e340c5f0a40cbc00975a8..de2ecd435b16a32dd0a92265b1ff938f1af29ef0 100644 --- a/lib/datasource/github-releases/index.ts +++ b/lib/datasource/github-releases/index.ts @@ -1,4 +1,3 @@ -import { logger } from '../../logger'; import * as packageCache from '../../util/cache/package'; import { GithubHttp } from '../../util/http/github'; import { GetReleasesConfig, ReleaseResult } from '../common'; @@ -27,7 +26,6 @@ type GithubRelease = { export async function getReleases({ lookupName: repo, }: GetReleasesConfig): Promise<ReleaseResult | null> { - let githubReleases: GithubRelease[]; const cachedResult = await packageCache.get<ReleaseResult>( cacheNamespace, repo @@ -36,19 +34,11 @@ export async function getReleases({ if (cachedResult) { return cachedResult; } - try { - const url = `https://api.github.com/repos/${repo}/releases?per_page=100`; - const res = await http.getJson<GithubRelease[]>(url, { - paginate: true, - }); - githubReleases = res.body; - } catch (err) /* istanbul ignore next */ { - logger.debug({ repo, err }, 'Error retrieving from github'); - } - // istanbul ignore if - if (!githubReleases) { - return null; - } + const url = `https://api.github.com/repos/${repo}/releases?per_page=100`; + const res = await http.getJson<GithubRelease[]>(url, { + paginate: true, + }); + const githubReleases = res.body; const dependency: ReleaseResult = { sourceUrl: 'https://github.com/' + repo, releases: null, diff --git a/lib/datasource/github-tags/index.ts b/lib/datasource/github-tags/index.ts index d2a385a42bafacaee90fa5e954370f8dbe430f03..2e0877a9f70b1097af88a7b83cf94a86e903dfaa 100644 --- a/lib/datasource/github-tags/index.ts +++ b/lib/datasource/github-tags/index.ts @@ -121,7 +121,6 @@ export async function getDigest( export async function getReleases({ lookupName: repo, }: GetReleasesConfig): Promise<ReleaseResult | null> { - let versions: string[]; const cachedResult = await packageCache.get<ReleaseResult>( cacheNamespace, getCacheKey(repo, 'tags') @@ -130,24 +129,17 @@ export async function getReleases({ if (cachedResult) { return cachedResult; } - try { - // tag - const url = `https://api.github.com/repos/${repo}/tags?per_page=100`; - type GitHubTag = { - name: string; - }[]; + // tag + const url = `https://api.github.com/repos/${repo}/tags?per_page=100`; + type GitHubTag = { + name: string; + }[]; - versions = ( - await http.getJson<GitHubTag>(url, { - paginate: true, - }) - ).body.map((o) => o.name); - } catch (err) { - logger.debug({ repo, err }, 'Error retrieving from github'); - } - if (!versions) { - return null; - } + const versions = ( + await http.getJson<GitHubTag>(url, { + paginate: true, + }) + ).body.map((o) => o.name); const dependency: ReleaseResult = { sourceUrl: 'https://github.com/' + repo, releases: null, diff --git a/lib/datasource/gitlab-tags/index.ts b/lib/datasource/gitlab-tags/index.ts index 59bff4283b83e691e1182fbef5023e515ac79a3d..22d481253e7b34ea73fefebcfb5a8a4941234789 100644 --- a/lib/datasource/gitlab-tags/index.ts +++ b/lib/datasource/gitlab-tags/index.ts @@ -1,5 +1,4 @@ import URL from 'url'; -import { logger } from '../../logger'; import * as packageCache from '../../util/cache/package'; import { GitlabHttp } from '../../util/http/gitlab'; import { GetReleasesConfig, ReleaseResult } from '../common'; @@ -27,7 +26,6 @@ export async function getReleases({ registryUrl: depHost, lookupName: repo, }: GetReleasesConfig): Promise<ReleaseResult | null> { - let gitlabTags: GitlabTag[]; const cachedResult = await packageCache.get<ReleaseResult>( cacheNamespace, getCacheKey(depHost, repo) @@ -39,27 +37,17 @@ export async function getReleases({ const urlEncodedRepo = encodeURIComponent(repo); - try { - // tag - const url = URL.resolve( - depHost, - `/api/v4/projects/${urlEncodedRepo}/repository/tags?per_page=100` - ); - - gitlabTags = ( - await gitlabApi.getJson<GitlabTag[]>(url, { - paginate: true, - }) - ).body; - } catch (err) { - // istanbul ignore next - logger.debug({ repo, err }, 'Error retrieving from Gitlab'); - } + // tag + const url = URL.resolve( + depHost, + `/api/v4/projects/${urlEncodedRepo}/repository/tags?per_page=100` + ); - // istanbul ignore if - if (!gitlabTags) { - return null; - } + const gitlabTags = ( + await gitlabApi.getJson<GitlabTag[]>(url, { + paginate: true, + }) + ).body; const dependency: ReleaseResult = { sourceUrl: URL.resolve(depHost, repo), diff --git a/lib/datasource/go/index.ts b/lib/datasource/go/index.ts index 0e658bacf267519855bb89b4af351275a826fa0b..c4411f08dcfeb6f676f35a7308c0f5a1974545d8 100644 --- a/lib/datasource/go/index.ts +++ b/lib/datasource/go/index.ts @@ -33,40 +33,25 @@ async function getDatasource(goModule: string): Promise<DataSource | null> { }; } const pkgUrl = `https://${goModule}?go-get=1`; - try { - const res = (await http.get(pkgUrl)).body; - const sourceMatch = regEx( - `<meta\\s+name="go-source"\\s+content="${goModule}\\s+([^\\s]+)` - ).exec(res); - if (sourceMatch) { - const [, goSourceUrl] = sourceMatch; - logger.debug({ goModule, goSourceUrl }, 'Go lookup source url'); - if (goSourceUrl && goSourceUrl.startsWith('https://github.com/')) { - return { - datasource: github.id, - lookupName: goSourceUrl - .replace('https://github.com/', '') - .replace(/\/$/, ''), - }; - } - } else { - logger.trace({ goModule }, 'No go-source header found'); - } - return null; - } catch (err) { - if (err.statusCode === 404 || err.code === 'ENOTFOUND') { - logger.debug( - { dependency: goModule }, - `Dependency lookup failure: not found` - ); - logger.debug({ - err, - }); - return null; + const res = (await http.get(pkgUrl)).body; + const sourceMatch = regEx( + `<meta\\s+name="go-source"\\s+content="${goModule}\\s+([^\\s]+)` + ).exec(res); + if (sourceMatch) { + const [, goSourceUrl] = sourceMatch; + logger.debug({ goModule, goSourceUrl }, 'Go lookup source url'); + if (goSourceUrl && goSourceUrl.startsWith('https://github.com/')) { + return { + datasource: github.id, + lookupName: goSourceUrl + .replace('https://github.com/', '') + .replace(/\/$/, ''), + }; } - logger.debug({ err, goModule }, 'go lookup failure: Unknown error'); - return null; + } else { + logger.trace({ goModule }, 'No go-source header found'); } + return null; } /** diff --git a/lib/datasource/gradle-version/index.ts b/lib/datasource/gradle-version/index.ts index f7ebc86dac1b2ffe8120f45df44b95e5d27781de..2492dbf3486ed7bacee92f9d4199f33da5f71ece 100644 --- a/lib/datasource/gradle-version/index.ts +++ b/lib/datasource/gradle-version/index.ts @@ -1,4 +1,3 @@ -import { logger } from '../../logger'; import { ExternalHostError } from '../../types/errors/external-host-error'; import { Http } from '../../util/http'; import { regEx } from '../../util/regex'; @@ -53,8 +52,7 @@ export async function getReleases({ if (err.host === 'services.gradle.org') { throw new ExternalHostError(err); } - logger.debug({ err }, 'gradle-version err'); - return null; + throw err; } const res: ReleaseResult = { diff --git a/lib/datasource/helm/index.ts b/lib/datasource/helm/index.ts index def7776dbc4f19b424f71421821fc8877743fb4e..1a54d7a1ee165722b91357683bfd4487f40f28d0 100644 --- a/lib/datasource/helm/index.ts +++ b/lib/datasource/helm/index.ts @@ -36,43 +36,13 @@ export async function getRepositoryData( return null; } } catch (err) { - // istanbul ignore if - if (err.code === 'ERR_INVALID_URL') { - logger.debug( - { helmRepository: repository }, - 'helm repository is not a valid URL - skipping' - ); - return null; - } - // istanbul ignore if - if ( - err.code === 'ENOTFOUND' || - err.code === 'EAI_AGAIN' || - err.code === 'ETIMEDOUT' - ) { - logger.debug({ err }, 'Could not connect to helm repository'); - return null; - } - if (err.statusCode === 404 || err.code === 'ENOTFOUND') { - logger.debug({ err }, 'Helm Chart not found'); - return null; - } if ( err.statusCode === 429 || (err.statusCode >= 500 && err.statusCode < 600) ) { throw new ExternalHostError(err); } - // istanbul ignore if - if (err.name === 'UnsupportedProtocolError') { - logger.debug({ repository }, 'Unsupported protocol'); - return null; - } - logger.warn( - { err }, - `helm datasource ${repository} lookup failure: Unknown error` - ); - return null; + throw err; } try { const doc = yaml.safeLoad(res.body, { json: true }); diff --git a/lib/datasource/hex/index.ts b/lib/datasource/hex/index.ts index e0ce145c7b0868114547b9cab81ab7ef697856c0..567fa45bb23574b2dc217ddc05e0aefd3ca54935 100644 --- a/lib/datasource/hex/index.ts +++ b/lib/datasource/hex/index.ts @@ -64,23 +64,12 @@ export async function getReleases({ return result; } catch (err) { - const errorData = { lookupName, err }; - if ( err.statusCode === 429 || (err.statusCode >= 500 && err.statusCode < 600) ) { throw new ExternalHostError(err); } - - if (err.statusCode === 401) { - logger.debug(errorData, 'Authorization error'); - } else if (err.statusCode === 404) { - logger.debug(errorData, 'Package lookup error'); - } else { - logger.warn(errorData, 'hex lookup failure: Unknown error'); - } + throw err; } - - return null; } diff --git a/lib/datasource/index.ts b/lib/datasource/index.ts index b8b2d2817ca14f743b10862c19c39125e9fbe055..8a5f628e05b2dcb0c06f626c6e8484e18418ef21 100644 --- a/lib/datasource/index.ts +++ b/lib/datasource/index.ts @@ -30,13 +30,17 @@ function load(datasource: string): Promise<Datasource> { type GetReleasesInternalConfig = GetReleasesConfig & GetPkgReleasesConfig; -// istanbul ignore next function logError(datasource, lookupName, err): void { - const { statusCode, url } = err; + const { statusCode, code: errCode, url } = err; if (statusCode === 404) { logger.debug({ datasource, lookupName, url }, 'Datasource 404'); } else if (statusCode === 401 || statusCode === 403) { logger.debug({ datasource, lookupName, url }, 'Datasource unauthorized'); + } else if (errCode) { + logger.debug( + { datasource, lookupName, url, errCode }, + 'Datasource connection error' + ); } else { logger.debug({ datasource, lookupName, err }, 'Datasource unknown error'); } diff --git a/lib/datasource/maven/index.ts b/lib/datasource/maven/index.ts index 636a9ea35db7da029de0ed6af0580efffcda4cde..e4e0bcfb4cd76d472056c98837d5ac2cf24a0a15 100644 --- a/lib/datasource/maven/index.ts +++ b/lib/datasource/maven/index.ts @@ -32,15 +32,7 @@ function getMavenUrl( repoUrl: string, path: string ): url.URL | null { - try { - return new url.URL(`${dependency.dependencyUrl}/${path}`, repoUrl); - } catch (err) { - logger.debug( - { err, dependency, repoUrl, path }, - `Error constructing URL for ${dependency.display}` - ); - } - return null; + return new url.URL(`${dependency.dependencyUrl}/${path}`, repoUrl); } async function downloadMavenXml( @@ -74,12 +66,7 @@ async function downloadMavenXml( return null; } - try { - return new XmlDocument(rawContent); - } catch (e) { - logger.debug(`Can not parse ${pkgUrl.href}`); - return null; - } + return new XmlDocument(rawContent); } async function getDependencyInfo( @@ -152,9 +139,6 @@ async function getVersionsFromMetadata( repoUrl: string ): Promise<string[] | null> { const metadataUrl = getMavenUrl(dependency, repoUrl, 'maven-metadata.xml'); - if (!metadataUrl) { - return null; - } const cacheNamespace = 'datasource-maven-metadata'; const cacheKey = metadataUrl.toString(); diff --git a/lib/datasource/nuget/v2.ts b/lib/datasource/nuget/v2.ts index 767a93e888641542450b47f456f132b96ac84ac7..fa2cb22ba3bb6971f998b14983cf446faabd9a9a 100644 --- a/lib/datasource/nuget/v2.ts +++ b/lib/datasource/nuget/v2.ts @@ -19,53 +19,45 @@ export async function getReleases( pkgName, releases: [], }; - try { - let pkgUrlList = `${feedUrl}/FindPackagesById()?id=%27${pkgName}%27&$select=Version,IsLatestVersion,ProjectUrl`; - do { - const pkgVersionsListRaw = await http.get(pkgUrlList); - const pkgVersionsListDoc = new XmlDocument(pkgVersionsListRaw.body); - - const pkgInfoList = pkgVersionsListDoc.childrenNamed('entry'); - - for (const pkgInfo of pkgInfoList) { - const pkgVersion = getPkgProp(pkgInfo, 'Version'); - dep.releases.push({ - version: pkgVersion, - }); - try { - const pkgIsLatestVersion = getPkgProp(pkgInfo, 'IsLatestVersion'); - if (pkgIsLatestVersion === 'true') { - const projectUrl = getPkgProp(pkgInfo, 'ProjectUrl'); - if (projectUrl) { - dep.sourceUrl = projectUrl; - } + let pkgUrlList = `${feedUrl}/FindPackagesById()?id=%27${pkgName}%27&$select=Version,IsLatestVersion,ProjectUrl`; + do { + const pkgVersionsListRaw = await http.get(pkgUrlList); + const pkgVersionsListDoc = new XmlDocument(pkgVersionsListRaw.body); + + const pkgInfoList = pkgVersionsListDoc.childrenNamed('entry'); + + for (const pkgInfo of pkgInfoList) { + const pkgVersion = getPkgProp(pkgInfo, 'Version'); + dep.releases.push({ + version: pkgVersion, + }); + try { + const pkgIsLatestVersion = getPkgProp(pkgInfo, 'IsLatestVersion'); + if (pkgIsLatestVersion === 'true') { + const projectUrl = getPkgProp(pkgInfo, 'ProjectUrl'); + if (projectUrl) { + dep.sourceUrl = projectUrl; } - } catch (err) /* istanbul ignore next */ { - logger.debug( - { err, pkgName, feedUrl }, - `nuget registry failure: can't parse pkg info for project url` - ); } + } catch (err) /* istanbul ignore next */ { + logger.debug( + { err, pkgName, feedUrl }, + `nuget registry failure: can't parse pkg info for project url` + ); } + } - const nextPkgUrlListLink = pkgVersionsListDoc - .childrenNamed('link') - .find((node) => node.attr.rel === 'next'); - - pkgUrlList = nextPkgUrlListLink ? nextPkgUrlListLink.attr.href : null; - } while (pkgUrlList !== null); + const nextPkgUrlListLink = pkgVersionsListDoc + .childrenNamed('link') + .find((node) => node.attr.rel === 'next'); - // dep not found if no release, so we can try next registry - if (dep.releases.length === 0) { - return null; - } + pkgUrlList = nextPkgUrlListLink ? nextPkgUrlListLink.attr.href : null; + } while (pkgUrlList !== null); - return dep; - } catch (err) { - logger.debug( - { err, pkgName, feedUrl }, - 'nuget registry failure: Unknown error' - ); + // dep not found if no release, so we can try next registry + if (dep.releases.length === 0) { return null; } + + return dep; } diff --git a/lib/datasource/nuget/v3.ts b/lib/datasource/nuget/v3.ts index 58f164e584ca7c556d99c3ebe159a8b10c63d2d9..a1227294aa4b8242b90a349923e8e009d8ecc2a0 100644 --- a/lib/datasource/nuget/v3.ts +++ b/lib/datasource/nuget/v3.ts @@ -68,68 +68,60 @@ export async function getReleases( pkgName, releases: [], }; + // TODO: fix types + const pkgUrlListRaw = await http.getJson<any>(queryUrl); + const match = pkgUrlListRaw.body.data.find( + (item) => item.id.toLowerCase() === pkgName.toLowerCase() + ); + // https://docs.microsoft.com/en-us/nuget/api/search-query-service-resource#search-result + if (!match) { + // There are no pkgName or releases in current feed + return null; + } + dep.releases = match.versions.map((item) => ({ + version: item.version, + })); + try { - // TODO: fix types - const pkgUrlListRaw = await http.getJson<any>(queryUrl); - const match = pkgUrlListRaw.body.data.find( - (item) => item.id.toLowerCase() === pkgName.toLowerCase() - ); - // https://docs.microsoft.com/en-us/nuget/api/search-query-service-resource#search-result - if (!match) { - // There are no pkgName or releases in current feed - return null; + // For nuget.org we have a way to get nuspec file + const sanitizedVersions = dep.releases + .map((release) => semver.valid(release.version)) + .filter(Boolean) + .filter((version) => !semver.prerelease(version)); + let lastVersion: string; + // istanbul ignore else + if (sanitizedVersions.length) { + // Use the last stable version we found + lastVersion = sanitizedVersions.pop(); + } else { + // Just use the last one from the list and hope for the best + lastVersion = [...dep.releases].pop().version; } - dep.releases = match.versions.map((item) => ({ - version: item.version, - })); - - try { - // For nuget.org we have a way to get nuspec file - const sanitizedVersions = dep.releases - .map((release) => semver.valid(release.version)) - .filter(Boolean) - .filter((version) => !semver.prerelease(version)); - let lastVersion: string; - // istanbul ignore else - if (sanitizedVersions.length) { - // Use the last stable version we found - lastVersion = sanitizedVersions.pop(); - } else { - // Just use the last one from the list and hope for the best - lastVersion = [...dep.releases].pop().version; + if (registryUrl.toLowerCase() === defaultNugetFeed.toLowerCase()) { + const nugetOrgApi = `https://api.nuget.org/v3-flatcontainer/${pkgName.toLowerCase()}/${lastVersion}/${pkgName.toLowerCase()}.nuspec`; + let metaresult: { body: string }; + try { + metaresult = await http.get(nugetOrgApi); + } catch (err) /* istanbul ignore next */ { + logger.debug( + `Cannot fetch metadata for ${pkgName} using popped version ${lastVersion}` + ); + return dep; } - if (registryUrl.toLowerCase() === defaultNugetFeed.toLowerCase()) { - const nugetOrgApi = `https://api.nuget.org/v3-flatcontainer/${pkgName.toLowerCase()}/${lastVersion}/${pkgName.toLowerCase()}.nuspec`; - let metaresult: { body: string }; - try { - metaresult = await http.get(nugetOrgApi); - } catch (err) /* istanbul ignore next */ { - logger.debug( - `Cannot fetch metadata for ${pkgName} using popped version ${lastVersion}` - ); - return dep; - } - const nuspec = new XmlDocument(metaresult.body); - const sourceUrl = nuspec.valueWithPath('metadata.repository@url'); - if (sourceUrl) { - dep.sourceUrl = sourceUrl; - } - } else if (match.projectUrl) { - dep.sourceUrl = match.projectUrl; + const nuspec = new XmlDocument(metaresult.body); + const sourceUrl = nuspec.valueWithPath('metadata.repository@url'); + if (sourceUrl) { + dep.sourceUrl = sourceUrl; } - } catch (err) /* istanbul ignore next */ { - logger.debug( - { err, pkgName, feedUrl }, - `nuget registry failure: can't parse pkg info for project url` - ); + } else if (match.projectUrl) { + dep.sourceUrl = match.projectUrl; } - - return dep; - } catch (err) { + } catch (err) /* istanbul ignore next */ { logger.debug( { err, pkgName, feedUrl }, - 'nuget registry failure: Unknown error' + `nuget registry failure: can't parse pkg info for project url` ); - return null; } + + return dep; } diff --git a/lib/datasource/orb/index.ts b/lib/datasource/orb/index.ts index b26c468dc45dcde9c3676d12a8219b7d234490b2..bf92ecea9ce659acdd4714ac844f90eaaa9d6447 100644 --- a/lib/datasource/orb/index.ts +++ b/lib/datasource/orb/index.ts @@ -39,42 +39,32 @@ export async function getReleases({ query: `{orb(name:"${lookupName}"){name, homeUrl, versions {version, createdAt}}}`, variables: {}, }; - try { - const res: OrbRelease = ( - await http.postJson<{ data: { orb: OrbRelease } }>(url, { - body, - }) - ).body.data.orb; - if (!res) { - logger.debug({ lookupName }, 'Failed to look up orb'); - return null; - } - // Simplify response before caching and returning - const dep: ReleaseResult = { - name: lookupName, - versions: {}, - releases: null, - }; - if (res.homeUrl && res.homeUrl.length) { - dep.homepage = res.homeUrl; - } - dep.homepage = - dep.homepage || `https://circleci.com/orbs/registry/orb/${lookupName}`; - dep.releases = res.versions.map(({ version, createdAt }) => ({ - version, - releaseTimestamp: createdAt || null, - })); - logger.trace({ dep }, 'dep'); - const cacheMinutes = 15; - await packageCache.set(cacheNamespace, cacheKey, dep, cacheMinutes); - return dep; - } catch (err) /* istanbul ignore next */ { - logger.debug({ err }, 'CircleCI Orb lookup error'); - if (err.statusCode === 404 || err.code === 'ENOTFOUND') { - logger.debug({ lookupName }, `CircleCI Orb lookup failure: not found`); - return null; - } - logger.warn({ lookupName }, 'CircleCI Orb lookup failure: Unknown error'); + const res: OrbRelease = ( + await http.postJson<{ data: { orb: OrbRelease } }>(url, { + body, + }) + ).body.data.orb; + if (!res) { + logger.debug({ lookupName }, 'Failed to look up orb'); return null; } + // Simplify response before caching and returning + const dep: ReleaseResult = { + name: lookupName, + versions: {}, + releases: null, + }; + if (res.homeUrl && res.homeUrl.length) { + dep.homepage = res.homeUrl; + } + dep.homepage = + dep.homepage || `https://circleci.com/orbs/registry/orb/${lookupName}`; + dep.releases = res.versions.map(({ version, createdAt }) => ({ + version, + releaseTimestamp: createdAt || null, + })); + logger.trace({ dep }, 'dep'); + const cacheMinutes = 15; + await packageCache.set(cacheNamespace, cacheKey, dep, cacheMinutes); + return dep; } diff --git a/lib/datasource/packagist/index.ts b/lib/datasource/packagist/index.ts index 78b8d175dbe5c4517d208774e3c158ad9cac2fad..ba425b8c8034bdeb81e89421a751d1618199fe34 100644 --- a/lib/datasource/packagist/index.ts +++ b/lib/datasource/packagist/index.ts @@ -49,63 +49,42 @@ interface RegistryMeta { } async function getRegistryMeta(regUrl: string): Promise<RegistryMeta | null> { - try { - const url = URL.resolve(regUrl.replace(/\/?$/, '/'), 'packages.json'); - const opts = getHostOpts(url); - const res = (await http.getJson<PackageMeta>(url, opts)).body; - const meta: RegistryMeta = { - providerPackages: {}, - }; - meta.packages = res.packages; - if (res.includes) { - meta.includesFiles = []; - for (const [name, val] of Object.entries(res.includes)) { - const file = { - key: name.replace(val.sha256, '%hash%'), - sha256: val.sha256, - }; - meta.includesFiles.push(file); - } - } - if (res['providers-url']) { - meta.providersUrl = res['providers-url']; - } - if (res['provider-includes']) { - meta.files = []; - for (const [key, val] of Object.entries(res['provider-includes'])) { - const file = { - key, - sha256: val.sha256, - }; - meta.files.push(file); - } - } - if (res.providers) { - for (const [key, val] of Object.entries(res.providers)) { - meta.providerPackages[key] = val.sha256; - } - } - return meta; - } catch (err) { - if (err.code === 'ETIMEDOUT') { - logger.debug({ regUrl }, 'Packagist timeout'); - return null; + const url = URL.resolve(regUrl.replace(/\/?$/, '/'), 'packages.json'); + const opts = getHostOpts(url); + const res = (await http.getJson<PackageMeta>(url, opts)).body; + const meta: RegistryMeta = { + providerPackages: {}, + }; + meta.packages = res.packages; + if (res.includes) { + meta.includesFiles = []; + for (const [name, val] of Object.entries(res.includes)) { + const file = { + key: name.replace(val.sha256, '%hash%'), + sha256: val.sha256, + }; + meta.includesFiles.push(file); } - if (err.statusCode === 401 || err.statusCode === 403) { - logger.debug({ regUrl }, 'Unauthorized Packagist repository'); - return null; + } + if (res['providers-url']) { + meta.providersUrl = res['providers-url']; + } + if (res['provider-includes']) { + meta.files = []; + for (const [key, val] of Object.entries(res['provider-includes'])) { + const file = { + key, + sha256: val.sha256, + }; + meta.files.push(file); } - if ( - err.statusCode === 404 && - err.url && - err.url.endsWith('/packages.json') - ) { - logger.debug({ regUrl }, 'Packagist repository not found'); - return null; + } + if (res.providers) { + for (const [key, val] of Object.entries(res.providers)) { + meta.providerPackages[key] = val.sha256; } - logger.warn({ err }, 'Packagist download error'); - return null; } + return meta; } interface PackagistFile { @@ -176,9 +155,6 @@ interface AllPackages { async function getAllPackages(regUrl: string): Promise<AllPackages | null> { const registryMeta = await getRegistryMeta(regUrl); - if (!registryMeta) { - return null; - } const { packages, providersUrl, @@ -266,9 +242,6 @@ async function packageLookup( return packagistResult; } const allPackages = await getAllCachedPackages(regUrl); - if (!allPackages) { - return null; - } const { packages, providersUrl, @@ -302,16 +275,6 @@ async function packageLookup( logger.trace({ dep }, 'dep'); return dep; } catch (err) /* istanbul ignore next */ { - if (err.statusCode === 404 || err.code === 'ENOTFOUND') { - logger.debug( - { dependency: name }, - `Dependency lookup failure: not found` - ); - logger.debug({ - err, - }); - return null; - } if (err.host === 'packagist.org') { if (err.code === 'ECONNRESET' || err.code === 'ETIMEDOUT') { throw new ExternalHostError(err); @@ -320,8 +283,7 @@ async function packageLookup( throw new ExternalHostError(err); } } - logger.warn({ err, name }, 'packagist registry failure: Unknown error'); - return null; + throw err; } } diff --git a/lib/datasource/pypi/index.ts b/lib/datasource/pypi/index.ts index a351082324e22cdbbceafb252271b55fda4d646d..56c3a9a605a4bad484ae02d627d1d77773ec338b 100644 --- a/lib/datasource/pypi/index.ts +++ b/lib/datasource/pypi/index.ts @@ -58,88 +58,74 @@ async function getDependency( hostUrl: string, compatibility: Record<string, string> ): Promise<ReleaseResult | null> { - try { - const lookupUrl = url.resolve(hostUrl, `${packageName}/json`); - const dependency: ReleaseResult = { releases: null }; - logger.trace({ lookupUrl }, 'Pypi api got lookup'); - const rep = await http.getJson<PypiJSON>(lookupUrl); - const dep = rep && rep.body; - if (!dep) { - logger.trace({ dependency: packageName }, 'pip package not found'); - return null; - } - logger.trace({ lookupUrl }, 'Got pypi api result'); - if ( - !(dep.info && normalizeName(dep.info.name) === normalizeName(packageName)) - ) { - logger.warn( - { lookupUrl, lookupName: packageName, returnedName: dep.info.name }, - 'Returned name does not match with requested name' - ); - return null; + const lookupUrl = url.resolve(hostUrl, `${packageName}/json`); + const dependency: ReleaseResult = { releases: null }; + logger.trace({ lookupUrl }, 'Pypi api got lookup'); + const rep = await http.getJson<PypiJSON>(lookupUrl); + const dep = rep && rep.body; + if (!dep) { + logger.trace({ dependency: packageName }, 'pip package not found'); + return null; + } + logger.trace({ lookupUrl }, 'Got pypi api result'); + if ( + !(dep.info && normalizeName(dep.info.name) === normalizeName(packageName)) + ) { + logger.warn( + { lookupUrl, lookupName: packageName, returnedName: dep.info.name }, + 'Returned name does not match with requested name' + ); + return null; + } + + if (dep.info?.home_page) { + dependency.homepage = dep.info.home_page; + if (github_repo_pattern.exec(dep.info.home_page)) { + dependency.sourceUrl = dep.info.home_page.replace('http://', 'https://'); } + } - if (dep.info?.home_page) { - dependency.homepage = dep.info.home_page; - if (github_repo_pattern.exec(dep.info.home_page)) { - dependency.sourceUrl = dep.info.home_page.replace( - 'http://', - 'https://' - ); + if (dep.info?.project_urls) { + for (const [name, projectUrl] of Object.entries(dep.info.project_urls)) { + const lower = name.toLowerCase(); + + if ( + !dependency.sourceUrl && + (lower.startsWith('repo') || + lower === 'code' || + lower === 'source' || + github_repo_pattern.exec(projectUrl)) + ) { + dependency.sourceUrl = projectUrl; } - } - if (dep.info?.project_urls) { - for (const [name, projectUrl] of Object.entries(dep.info.project_urls)) { - const lower = name.toLowerCase(); - - if ( - !dependency.sourceUrl && - (lower.startsWith('repo') || - lower === 'code' || - lower === 'source' || - github_repo_pattern.exec(projectUrl)) - ) { - dependency.sourceUrl = projectUrl; - } - - if ( - !dependency.changelogUrl && - ([ - 'changelog', - 'change log', - 'changes', - 'release notes', - 'news', - "what's new", - ].includes(lower) || - changelogFilenameRegex.exec(lower)) - ) { - // from https://github.com/pypa/warehouse/blob/418c7511dc367fb410c71be139545d0134ccb0df/warehouse/templates/packaging/detail.html#L24 - dependency.changelogUrl = projectUrl; - } + if ( + !dependency.changelogUrl && + ([ + 'changelog', + 'change log', + 'changes', + 'release notes', + 'news', + "what's new", + ].includes(lower) || + changelogFilenameRegex.exec(lower)) + ) { + // from https://github.com/pypa/warehouse/blob/418c7511dc367fb410c71be139545d0134ccb0df/warehouse/templates/packaging/detail.html#L24 + dependency.changelogUrl = projectUrl; } } + } - dependency.releases = []; - if (dep.releases) { - const versions = compatibleVersions(dep.releases, compatibility); - dependency.releases = versions.map((version) => ({ - version, - releaseTimestamp: (dep.releases[version][0] || {}).upload_time, - })); - } - return dependency; - } catch (err) { - logger.debug( - 'pypi dependency not found: ' + - packageName + - '(searching in ' + - hostUrl + - ')' - ); - return null; + dependency.releases = []; + if (dep.releases) { + const versions = compatibleVersions(dep.releases, compatibility); + dependency.releases = versions.map((version) => ({ + version, + releaseTimestamp: (dep.releases[version][0] || {}).upload_time, + })); } + return dependency; } function extractVersionFromLinkText( @@ -174,40 +160,29 @@ async function getSimpleDependency( hostUrl: string ): Promise<ReleaseResult | null> { const lookupUrl = url.resolve(hostUrl, `${packageName}`); - try { - const dependency: ReleaseResult = { releases: null }; - const response = await http.get(lookupUrl); - const dep = response && response.body; - if (!dep) { - logger.trace({ dependency: packageName }, 'pip package not found'); - return null; - } - const root: HTMLElement = parse(dep.replace(/<\/?pre>/, '')) as any; - const links = root.querySelectorAll('a'); - const versions = new Set<string>(); - for (const link of Array.from(links)) { - const result = extractVersionFromLinkText(link.text, packageName); - if (result) { - versions.add(result); - } - } - dependency.releases = []; - if (versions && versions.size > 0) { - dependency.releases = [...versions].map((version) => ({ - version, - })); - } - return dependency; - } catch (err) { - logger.debug( - 'pypi dependency not found: ' + - packageName + - '(searching in ' + - hostUrl + - ')' - ); + const dependency: ReleaseResult = { releases: null }; + const response = await http.get(lookupUrl); + const dep = response && response.body; + if (!dep) { + logger.trace({ dependency: packageName }, 'pip package not found'); return null; } + const root: HTMLElement = parse(dep.replace(/<\/?pre>/, '')) as any; + const links = root.querySelectorAll('a'); + const versions = new Set<string>(); + for (const link of Array.from(links)) { + const result = extractVersionFromLinkText(link.text, packageName); + if (result) { + versions.add(result); + } + } + dependency.releases = []; + if (versions && versions.size > 0) { + dependency.releases = [...versions].map((version) => ({ + version, + })); + } + return dependency; } export async function getReleases({ diff --git a/lib/datasource/rubygems/errors.ts b/lib/datasource/rubygems/errors.ts deleted file mode 100644 index 7c9b7971d88e09a43fa339e9aaf60c39388f9ddb..0000000000000000000000000000000000000000 --- a/lib/datasource/rubygems/errors.ts +++ /dev/null @@ -1,17 +0,0 @@ -const UNAUTHORIZED = 401; -const FORBIDDEN = 403; - -const NOT_FOUND = 404; - -const REQUEST_TIMEOUT = 408; -const TOO_MANY_REQUEST = 429; -const SERVICE_UNAVAILABLE = 503; - -export { - UNAUTHORIZED, - FORBIDDEN, - NOT_FOUND, - REQUEST_TIMEOUT, - TOO_MANY_REQUEST, - SERVICE_UNAVAILABLE, -}; diff --git a/lib/datasource/rubygems/get.ts b/lib/datasource/rubygems/get.ts index 91e72767f0d13698d2459b09c182195a4a4326ae..55e1d4d2f0e51f2474e105d013988f6093029dc4 100644 --- a/lib/datasource/rubygems/get.ts +++ b/lib/datasource/rubygems/get.ts @@ -1,37 +1,15 @@ import { OutgoingHttpHeaders } from 'http'; import { logger } from '../../logger'; import { Http } from '../../util/http'; -import { maskToken } from '../../util/mask'; import { ensureTrailingSlash } from '../../util/url'; import { ReleaseResult } from '../common'; import { id } from './common'; -import { FORBIDDEN, NOT_FOUND, UNAUTHORIZED } from './errors'; const http = new Http(id); const INFO_PATH = '/api/v1/gems'; const VERSIONS_PATH = '/api/v1/versions'; -// istanbul ignore next -const processError = ({ err, ...rest }): null => { - const { code, statusCode, headers = {} } = err; - const data = { - ...rest, - err, - statusCode, - token: maskToken(headers.authorization) || 'none', - }; - - if (code === 'ENOTFOUND' || statusCode === NOT_FOUND) { - logger.debug(data, 'RubyGems lookup failure: not found'); - } else if (statusCode === FORBIDDEN || statusCode === UNAUTHORIZED) { - logger.debug(data, 'RubyGems lookup failure: authentication failed'); - } else { - logger.debug(data, 'RubyGems lookup failure: unknown reason'); - } - return null; -}; - const getHeaders = (): OutgoingHttpHeaders => { return { hostType: id }; }; @@ -55,47 +33,43 @@ export const getDependency = async ({ registry, }): Promise<ReleaseResult | null> => { logger.debug({ dependency }, 'RubyGems lookup for dependency'); - try { - const info = await fetch({ dependency, registry, path: INFO_PATH }); - if (!info) { - logger.debug({ dependency }, 'RubyGems package not found.'); - return null; - } + const info = await fetch({ dependency, registry, path: INFO_PATH }); + if (!info) { + logger.debug({ dependency }, 'RubyGems package not found.'); + return null; + } - if (dependency.toLowerCase() !== info.name.toLowerCase()) { - logger.warn( - { lookup: dependency, returned: info.name }, - 'Lookup name does not match with returned.' - ); - return null; - } + if (dependency.toLowerCase() !== info.name.toLowerCase()) { + logger.warn( + { lookup: dependency, returned: info.name }, + 'Lookup name does not match with returned.' + ); + return null; + } - const versions = - (await fetch({ dependency, registry, path: VERSIONS_PATH })) || []; + const versions = + (await fetch({ dependency, registry, path: VERSIONS_PATH })) || []; - const releases = versions.map( - ({ - number: version, - platform: rubyPlatform, - created_at: releaseTimestamp, - rubygems_version: rubygemsVersion, - ruby_version: rubyVersion, - }) => ({ - version, - rubyPlatform, - releaseTimestamp, - rubygemsVersion, - rubyVersion, - }) - ); + const releases = versions.map( + ({ + number: version, + platform: rubyPlatform, + created_at: releaseTimestamp, + rubygems_version: rubygemsVersion, + ruby_version: rubyVersion, + }) => ({ + version, + rubyPlatform, + releaseTimestamp, + rubygemsVersion, + rubyVersion, + }) + ); - return { - releases, - homepage: info.homepage_uri, - sourceUrl: info.source_code_uri, - changelogUrl: info.changelog_uri, - }; - } catch (err) { - return processError({ err, registry, dependency }); - } + return { + releases, + homepage: info.homepage_uri, + sourceUrl: info.source_code_uri, + changelogUrl: info.changelog_uri, + }; }; diff --git a/lib/datasource/terraform-module/index.ts b/lib/datasource/terraform-module/index.ts index 217cdcb9827294d71577e1fe40c03d39e4b86834..50c7a7b90d016ec2309283582bd1524ba003157a 100644 --- a/lib/datasource/terraform-module/index.ts +++ b/lib/datasource/terraform-module/index.ts @@ -101,25 +101,11 @@ export async function getReleases({ await packageCache.set(cacheNamespace, pkgUrl, dep, cacheMinutes); return dep; } catch (err) { - if (err.statusCode === 404 || err.code === 'ENOTFOUND') { - logger.debug( - { lookupName }, - `Terraform registry lookup failure: not found` - ); - logger.debug({ - err, - }); - return null; - } const failureCodes = ['EAI_AGAIN']; // istanbul ignore if if (failureCodes.includes(err.code)) { throw new ExternalHostError(err); } - logger.warn( - { err, lookupName }, - 'Terraform registry failure: Unknown error' - ); - return null; + throw err; } } diff --git a/lib/datasource/terraform-provider/index.ts b/lib/datasource/terraform-provider/index.ts index 5ba096a98e3388f016c38c6fc4d11bfd613f1fcc..64be934edfee1bc468a3ec210f42ddd2ad701ed8 100644 --- a/lib/datasource/terraform-provider/index.ts +++ b/lib/datasource/terraform-provider/index.ts @@ -36,33 +36,22 @@ async function queryRegistry( registryURL: string, repository: string ): Promise<ReleaseResult> { - try { - const backendURL = `${registryURL}/v1/providers/${repository}`; - const res = (await http.getJson<TerraformProvider>(backendURL)).body; - const dep: ReleaseResult = { - name: repository, - versions: {}, - releases: null, - }; - if (res.source) { - dep.sourceUrl = res.source; - } - dep.releases = res.versions.map((version) => ({ - version, - })); - dep.homepage = `${registryURL}/providers/${repository}`; - logger.trace({ dep }, 'dep'); - return dep; - } catch (err) { - logger.debug( - { lookupName }, - `Terraform registry ("${registryURL}") lookup failure: not found` - ); - logger.debug({ - err, - }); - return null; + const backendURL = `${registryURL}/v1/providers/${repository}`; + const res = (await http.getJson<TerraformProvider>(backendURL)).body; + const dep: ReleaseResult = { + name: repository, + versions: {}, + releases: null, + }; + if (res.source) { + dep.sourceUrl = res.source; } + dep.releases = res.versions.map((version) => ({ + version, + })); + dep.homepage = `${registryURL}/providers/${repository}`; + logger.trace({ dep }, 'dep'); + return dep; } async function queryReleaseBackend( @@ -72,32 +61,20 @@ async function queryReleaseBackend( ): Promise<ReleaseResult> { const backendLookUpName = `terraform-provider-${lookupName}`; const backendURL = registryURL + `/index.json`; - try { - const res = ( - await http.getJson<TerraformProviderReleaseBackend>(backendURL) - ).body; - const dep: ReleaseResult = { - name: repository, - versions: {}, - releases: null, - }; - dep.releases = Object.keys(res[backendLookUpName].versions).map( - (version) => ({ - version, - }) - ); - logger.trace({ dep }, 'dep'); - return dep; - } catch (err) { - logger.debug( - { lookupName }, - `Terraform registry ("${registryURL}") lookup failure: not found` - ); - logger.debug({ - err, - }); - return null; - } + const res = (await http.getJson<TerraformProviderReleaseBackend>(backendURL)) + .body; + const dep: ReleaseResult = { + name: repository, + versions: {}, + releases: null, + }; + dep.releases = Object.keys(res[backendLookUpName].versions).map( + (version) => ({ + version, + }) + ); + logger.trace({ dep }, 'dep'); + return dep; } /**