From b3c8e19a7aec4fd27a7afc5760cc309f6b1308b2 Mon Sep 17 00:00:00 2001
From: Aiqiao Yan <aiqiaoy@MININT-K6RVDNE.europe.corp.microsoft.com>
Date: Tue, 12 May 2020 14:47:31 -0400
Subject: [PATCH] Attempt to fix the test

---
 packages/cache/package-lock.json              |  6 ++++
 packages/cache/package.json                   |  1 +
 packages/cache/src/cache.ts                   | 28 +++++++++++++++----
 .../cache/src/internal/cacheHttpClient.ts     |  6 ++--
 packages/cache/src/internal/contracts.d.ts    |  2 +-
 5 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/packages/cache/package-lock.json b/packages/cache/package-lock.json
index 4e2de82a..9d8b6cbf 100644
--- a/packages/cache/package-lock.json
+++ b/packages/cache/package-lock.json
@@ -77,6 +77,12 @@
 			"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
 			"integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg=="
 		},
+		"typescript": {
+			"version": "3.8.3",
+			"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.8.3.tgz",
+			"integrity": "sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==",
+			"dev": true
+		},
 		"uuid": {
 			"version": "3.4.0",
 			"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz",
diff --git a/packages/cache/package.json b/packages/cache/package.json
index 2ee2d9bb..fea57f0b 100644
--- a/packages/cache/package.json
+++ b/packages/cache/package.json
@@ -44,6 +44,7 @@
     "uuid": "^3.3.3"
   },
   "devDependencies": {
+    "typescript": "^3.8.3",
     "@types/uuid": "^3.4.5"
   }
 }
diff --git a/packages/cache/src/cache.ts b/packages/cache/src/cache.ts
index 39eaf6de..5f55c82b 100644
--- a/packages/cache/src/cache.ts
+++ b/packages/cache/src/cache.ts
@@ -5,9 +5,23 @@ import * as cacheHttpClient from './internal/cacheHttpClient'
 import {createTar, extractTar} from './internal/tar'
 import {UploadOptions} from './options'
 
+export class ValidationError extends Error {
+  constructor(message: string) {
+    super(message)
+    this.name = 'ValidationError'
+  }
+}
+
+export class ReserveCacheError extends Error {
+  constructor(message: string) {
+    super(message)
+    this.name = 'ReserveCacheError'
+  }
+}
+
 function checkPaths(paths: string[]): void {
   if (!paths || paths.length === 0) {
-    throw new Error(
+    throw new ValidationError(
       `Path Validation Error: At least one directory or file path is required`
     )
   }
@@ -15,13 +29,15 @@ function checkPaths(paths: string[]): void {
 
 function checkKey(key: string): void {
   if (key.length > 512) {
-    throw new Error(
+    throw new ValidationError(
       `Key Validation Error: ${key} cannot be larger than 512 characters.`
     )
   }
   const regex = /^[^,]*$/
   if (!regex.test(key)) {
-    throw new Error(`Key Validation Error: ${key} cannot contain commas.`)
+    throw new ValidationError(
+      `Key Validation Error: ${key} cannot contain commas.`
+    )
   }
 }
 
@@ -47,7 +63,7 @@ export async function restoreCache(
   core.debug(JSON.stringify(keys))
 
   if (keys.length > 10) {
-    throw new Error(
+    throw new ValidationError(
       `Key Validation Error: Keys are limited to a maximum of 10.`
     )
   }
@@ -121,13 +137,13 @@ export async function saveCache(
     compressionMethod
   })
   if (cacheId === -1) {
-    throw new Error(
+    throw new ReserveCacheError(
       `Unable to reserve cache with key ${key}, another job may be creating this cache.`
     )
   }
   core.debug(`Cache ID: ${cacheId}`)
-  const cachePaths = await utils.resolvePaths(paths)
 
+  const cachePaths = await utils.resolvePaths(paths)
   core.debug('Cache Paths:')
   core.debug(`${JSON.stringify(cachePaths)}`)
 
diff --git a/packages/cache/src/internal/cacheHttpClient.ts b/packages/cache/src/internal/cacheHttpClient.ts
index a3b9633a..43692fa7 100644
--- a/packages/cache/src/internal/cacheHttpClient.ts
+++ b/packages/cache/src/internal/cacheHttpClient.ts
@@ -15,7 +15,7 @@ import * as utils from './cacheUtils'
 import {CompressionMethod, SocketTimeout} from './constants'
 import {
   ArtifactCacheEntry,
-  CacheOptions,
+  InternalCacheOptions,
   CommitCacheRequest,
   ReserveCacheRequest,
   ReserveCacheResponse
@@ -180,7 +180,7 @@ export async function retryHttpClientResponse<T>(
 export async function getCacheEntry(
   keys: string[],
   paths: string[],
-  options?: CacheOptions
+  options?: InternalCacheOptions
 ): Promise<ArtifactCacheEntry | null> {
   const httpClient = createHttpClient()
   const version = getCacheVersion(paths, options?.compressionMethod)
@@ -258,7 +258,7 @@ export async function downloadCache(
 export async function reserveCache(
   key: string,
   paths: string[],
-  options?: CacheOptions
+  options?: InternalCacheOptions
 ): Promise<number> {
   const httpClient = createHttpClient()
   const version = getCacheVersion(paths, options?.compressionMethod)
diff --git a/packages/cache/src/internal/contracts.d.ts b/packages/cache/src/internal/contracts.d.ts
index ca3f3620..80484769 100644
--- a/packages/cache/src/internal/contracts.d.ts
+++ b/packages/cache/src/internal/contracts.d.ts
@@ -20,6 +20,6 @@ export interface ReserveCacheResponse {
   cacheId: number
 }
 
-export interface CacheOptions {
+export interface InternalCacheOptions {
   compressionMethod?: CompressionMethod
 }