From 65839b7862e915082f245c6a734920ba965e1b08 Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Tue, 2 Jun 2020 12:46:37 +0200 Subject: [PATCH] fix(git-submodules): add try-catch around extract phase --- lib/manager/git-submodules/extract.ts | 77 ++++++++++++++++----------- 1 file changed, 45 insertions(+), 32 deletions(-) diff --git a/lib/manager/git-submodules/extract.ts b/lib/manager/git-submodules/extract.ts index d346a8301e..dabe8a8926 100644 --- a/lib/manager/git-submodules/extract.ts +++ b/lib/manager/git-submodules/extract.ts @@ -3,6 +3,7 @@ import Git from 'simple-git/promise'; import upath from 'upath'; import * as datasourceGitSubmodules from '../../datasource/git-submodules'; +import { logger } from '../../logger'; import { ManagerConfig, PackageFile } from '../common'; type GitModule = { @@ -52,26 +53,28 @@ async function getModules( git: Git.SimpleGit, gitModulesPath: string ): Promise<GitModule[]> { - const modules = ( - (await git.raw([ - 'config', - '--file', - gitModulesPath, - '--get-regexp', - 'path', - ])) ?? /* istanbul ignore next: should never happen */ '' - ) - .trim() - .split(/\n/) - .filter((s) => !!s); - const res: GitModule[] = []; + try { + const modules = ( + (await git.raw([ + 'config', + '--file', + gitModulesPath, + '--get-regexp', + 'path', + ])) ?? /* istanbul ignore next: should never happen */ '' + ) + .trim() + .split(/\n/) + .filter((s) => !!s); - for (const line of modules) { - const [, name, path] = line.split(/submodule\.(.+?)\.path\s(.+)/); - res.push({ name, path }); + for (const line of modules) { + const [, name, path] = line.split(/submodule\.(.+?)\.path\s(.+)/); + res.push({ name, path }); + } + } catch (err) /* istanbul ignore next */ { + logger.warn({ err }, 'Error getting git submodules during extract'); } - return res; } @@ -89,21 +92,31 @@ export default async function extractPackageFile( return null; } - const deps = await Promise.all( - depNames.map(async ({ name, path }) => { - const [currentValue] = (await git.subModule(['status', path])) - .trim() - .split(/[+\s]/); - const submoduleBranch = await getBranch(gitModulesPath, name); - const subModuleUrl = await getUrl(git, gitModulesPath, name); - return { - depName: path, - registryUrls: [subModuleUrl, submoduleBranch], - currentValue, - currentDigest: currentValue, - }; - }) - ); + const deps = ( + await Promise.all( + depNames.map(async ({ name, path }) => { + try { + const [currentValue] = (await git.subModule(['status', path])) + .trim() + .split(/[+\s]/); + const submoduleBranch = await getBranch(gitModulesPath, name); + const subModuleUrl = await getUrl(git, gitModulesPath, name); + return { + depName: path, + registryUrls: [subModuleUrl, submoduleBranch], + currentValue, + currentDigest: currentValue, + }; + } catch (err) /* istanbul ignore next */ { + logger.warn( + { err }, + 'Error mapping git submodules during extraction' + ); + return null; + } + }) + ) + ).filter(Boolean); return { deps, datasource: datasourceGitSubmodules.id }; } -- GitLab