From 87dc1d0fe374caa0e96b199b7a344da334f28bfb Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Tue, 21 Dec 2021 16:12:09 +0100
Subject: [PATCH] fix: check for matchResult

---
 .../npm/update/locked-dependency/yarn-lock/replace.ts    | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/lib/manager/npm/update/locked-dependency/yarn-lock/replace.ts b/lib/manager/npm/update/locked-dependency/yarn-lock/replace.ts
index f2e9adfc68..7e09f3c835 100644
--- a/lib/manager/npm/update/locked-dependency/yarn-lock/replace.ts
+++ b/lib/manager/npm/update/locked-dependency/yarn-lock/replace.ts
@@ -1,3 +1,4 @@
+import { logger } from '../../../../../logger';
 import { regEx } from '../../../../../util/regex';
 
 export function replaceConstraintVersion(
@@ -16,6 +17,14 @@ export function replaceConstraintVersion(
   const matchString = `(${escaped}((",|,)[^\n:]+)?:\n)(.*\n)*?(\\s+dependencies|\n[@a-z])`;
   // yarn will fill in the details later
   const matchResult = regEx(matchString).exec(lockFileContent);
+  // istanbul ignore if
+  if (!matchResult) {
+    logger.debug(
+      { depName, constraint, newVersion },
+      'Could not find constraint in lock file'
+    );
+    return lockFileContent;
+  }
   let constraintLine = matchResult[1];
   if (newConstraint) {
     const newDepNameConstraint = `${depName}@${newConstraint}`;
-- 
GitLab