From 9a74eb4e6473f91fbde564f97c2662fd1dc4875c Mon Sep 17 00:00:00 2001
From: Dmitry Shibanov <dmitry-shibanov@github.com>
Date: Mon, 27 Dec 2021 12:34:06 +0300
Subject: [PATCH] Throw error only if exit code is note zero.  (#358)

---
 .github/workflows/licensed.yml |  2 +-
 dist/cache-save/index.js       |  7 +++++--
 dist/setup/index.js            |  7 +++++--
 src/cache-utils.ts             | 11 +++++++++--
 4 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/.github/workflows/licensed.yml b/.github/workflows/licensed.yml
index 4c1dfe5f..4f485f5f 100644
--- a/.github/workflows/licensed.yml
+++ b/.github/workflows/licensed.yml
@@ -18,7 +18,7 @@ jobs:
       - name: Install licensed
         run: |
           cd $RUNNER_TEMP
-          curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/2.12.2/licensed-2.12.2-linux-x64.tar.gz
+          curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/3.3.1/licensed-3.3.1-linux-x64.tar.gz
           sudo tar -xzf licensed.tar.gz
           sudo mv licensed /usr/local/bin/licensed
       - run: licensed status
diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js
index 2a86dfeb..b24c7c9c 100644
--- a/dist/cache-save/index.js
+++ b/dist/cache-save/index.js
@@ -3836,8 +3836,11 @@ exports.supportedPackageManagers = {
     }
 };
 exports.getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () {
-    const { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand);
-    if (stderr) {
+    let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true });
+    if (exitCode) {
+        stderr = !stderr.trim()
+            ? `The '${toolCommand}' command failed with exit code: ${exitCode}`
+            : stderr;
         throw new Error(stderr);
     }
     return stdout.trim();
diff --git a/dist/setup/index.js b/dist/setup/index.js
index 1dc2f2f5..c6a63f28 100644
--- a/dist/setup/index.js
+++ b/dist/setup/index.js
@@ -46207,8 +46207,11 @@ exports.supportedPackageManagers = {
     }
 };
 exports.getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () {
-    const { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand);
-    if (stderr) {
+    let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true });
+    if (exitCode) {
+        stderr = !stderr.trim()
+            ? `The '${toolCommand}' command failed with exit code: ${exitCode}`
+            : stderr;
         throw new Error(stderr);
     }
     return stdout.trim();
diff --git a/src/cache-utils.ts b/src/cache-utils.ts
index ebea9a75..36531bd5 100644
--- a/src/cache-utils.ts
+++ b/src/cache-utils.ts
@@ -30,9 +30,16 @@ export const supportedPackageManagers: SupportedPackageManagers = {
 };
 
 export const getCommandOutput = async (toolCommand: string) => {
-  const {stdout, stderr, exitCode} = await exec.getExecOutput(toolCommand);
+  let {stdout, stderr, exitCode} = await exec.getExecOutput(
+    toolCommand,
+    undefined,
+    {ignoreReturnCode: true}
+  );
 
-  if (stderr) {
+  if (exitCode) {
+    stderr = !stderr.trim()
+      ? `The '${toolCommand}' command failed with exit code: ${exitCode}`
+      : stderr;
     throw new Error(stderr);
   }