From 10d44aa11466dde0da7762ba90f7024f2cbec9ef Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Thu, 24 Nov 2022 13:26:27 -0500 Subject: [PATCH] Improve error handling of case where match is not found Signed-off-by: Sebastian Malton --- .../compute-unix-shell-environment.injectable.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/features/shell-sync/main/compute-unix-shell-environment.injectable.ts b/src/features/shell-sync/main/compute-unix-shell-environment.injectable.ts index bd8935bf63..e0f2b2aeb1 100644 --- a/src/features/shell-sync/main/compute-unix-shell-environment.injectable.ts +++ b/src/features/shell-sync/main/compute-unix-shell-environment.injectable.ts @@ -149,11 +149,18 @@ const computeUnixShellEnvironmentInjectable = getInjectable({ try { const rawOutput = Buffer.concat(stdout).toString("utf-8"); - logger.info(`[UNIX-SHELL-ENV]: got the following output`, { rawOutput }); + logger.debug(`[UNIX-SHELL-ENV]: got the following output`, { rawOutput }); - const match = regex.exec(rawOutput); - const strippedRawOutput = match ? match[1] : "{}"; - const resolvedEnv = JSON.parse(strippedRawOutput) as Partial>; + const matchedOutput = regex.exec(rawOutput)?.[1]; + + if (!matchedOutput) { + return resolve({ + callWasSuccessful: false, + error: "Something has blocked the shell from producing the environement variables", + }); + } + + const resolvedEnv = JSON.parse(matchedOutput) as Partial>; resetEnvPairs(resolvedEnv); resolve({