From 2cc6fa841b61777e30a77bb3a31a9559acb2bdc0 Mon Sep 17 00:00:00 2001
From: Birunthan Mohanathas <birunthan@mohanathas.com>
Date: Sat, 2 Nov 2019 20:51:48 -0600
Subject: [PATCH] Stop warning when cache is not found

The cache not being found is a common situation so very visible warning
is a little too much.
---
 src/cacheHttpClient.ts |  6 ++----
 src/restore.ts         | 12 +++++++++---
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/cacheHttpClient.ts b/src/cacheHttpClient.ts
index cebbdc0..30b5009 100644
--- a/src/cacheHttpClient.ts
+++ b/src/cacheHttpClient.ts
@@ -10,7 +10,7 @@ import { ArtifactCacheEntry } from "./contracts";
 
 export async function getCacheEntry(
     keys: string[]
-): Promise<ArtifactCacheEntry> {
+): Promise<ArtifactCacheEntry | null> {
     const cacheUrl = getCacheUrl();
     const token = process.env["ACTIONS_RUNTIME_TOKEN"] || "";
     const bearerCredentialHandler = new BearerCredentialHandler(token);
@@ -28,9 +28,7 @@ export async function getCacheEntry(
         getRequestOptions()
     );
     if (response.statusCode === 204) {
-        throw new Error(
-            `Cache not found for input keys: ${JSON.stringify(keys)}.`
-        );
+        return null;
     }
     if (response.statusCode !== 200) {
         throw new Error(`Cache service responded with ${response.statusCode}`);
diff --git a/src/restore.ts b/src/restore.ts
index 66a45aa..b115b08 100644
--- a/src/restore.ts
+++ b/src/restore.ts
@@ -49,14 +49,20 @@ async function run() {
         }
 
         try {
+            const cacheEntry = await cacheHttpClient.getCacheEntry(keys);
+            if (!cacheEntry) {
+                core.info(
+                    `Cache not found for input keys: ${JSON.stringify(keys)}.`
+                );
+                return;
+            }
+
             let archivePath = path.join(
                 await utils.createTempDirectory(),
                 "cache.tgz"
             );
             core.debug(`Archive Path: ${archivePath}`);
 
-            const cacheEntry = await cacheHttpClient.getCacheEntry(keys);
-
             // Store the cache result
             utils.setCacheState(cacheEntry);
 
@@ -92,7 +98,7 @@ async function run() {
             utils.setCacheHitOutput(isExactKeyMatch);
 
             core.info(
-                `Cache restored from key:${cacheEntry && cacheEntry.cacheKey}`
+                `Cache restored from key: ${cacheEntry && cacheEntry.cacheKey}`
             );
         } catch (error) {
             core.warning(error.message);