Skip to content

Commit b3c8e19

Browse files
Aiqiao YanAiqiao Yan
authored andcommitted
Attempt to fix the test
1 parent 1413cd0 commit b3c8e19

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

packages/cache/package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cache/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"uuid": "^3.3.3"
4545
},
4646
"devDependencies": {
47+
"typescript": "^3.8.3",
4748
"@types/uuid": "^3.4.5"
4849
}
4950
}

packages/cache/src/cache.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,39 @@ import * as cacheHttpClient from './internal/cacheHttpClient'
55
import {createTar, extractTar} from './internal/tar'
66
import {UploadOptions} from './options'
77

8+
export class ValidationError extends Error {
9+
constructor(message: string) {
10+
super(message)
11+
this.name = 'ValidationError'
12+
}
13+
}
14+
15+
export class ReserveCacheError extends Error {
16+
constructor(message: string) {
17+
super(message)
18+
this.name = 'ReserveCacheError'
19+
}
20+
}
21+
822
function checkPaths(paths: string[]): void {
923
if (!paths || paths.length === 0) {
10-
throw new Error(
24+
throw new ValidationError(
1125
`Path Validation Error: At least one directory or file path is required`
1226
)
1327
}
1428
}
1529

1630
function checkKey(key: string): void {
1731
if (key.length > 512) {
18-
throw new Error(
32+
throw new ValidationError(
1933
`Key Validation Error: ${key} cannot be larger than 512 characters.`
2034
)
2135
}
2236
const regex = /^[^,]*$/
2337
if (!regex.test(key)) {
24-
throw new Error(`Key Validation Error: ${key} cannot contain commas.`)
38+
throw new ValidationError(
39+
`Key Validation Error: ${key} cannot contain commas.`
40+
)
2541
}
2642
}
2743

@@ -47,7 +63,7 @@ export async function restoreCache(
4763
core.debug(JSON.stringify(keys))
4864

4965
if (keys.length > 10) {
50-
throw new Error(
66+
throw new ValidationError(
5167
`Key Validation Error: Keys are limited to a maximum of 10.`
5268
)
5369
}
@@ -121,13 +137,13 @@ export async function saveCache(
121137
compressionMethod
122138
})
123139
if (cacheId === -1) {
124-
throw new Error(
140+
throw new ReserveCacheError(
125141
`Unable to reserve cache with key ${key}, another job may be creating this cache.`
126142
)
127143
}
128144
core.debug(`Cache ID: ${cacheId}`)
129-
const cachePaths = await utils.resolvePaths(paths)
130145

146+
const cachePaths = await utils.resolvePaths(paths)
131147
core.debug('Cache Paths:')
132148
core.debug(`${JSON.stringify(cachePaths)}`)
133149

packages/cache/src/internal/cacheHttpClient.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import * as utils from './cacheUtils'
1515
import {CompressionMethod, SocketTimeout} from './constants'
1616
import {
1717
ArtifactCacheEntry,
18-
CacheOptions,
18+
InternalCacheOptions,
1919
CommitCacheRequest,
2020
ReserveCacheRequest,
2121
ReserveCacheResponse
@@ -180,7 +180,7 @@ export async function retryHttpClientResponse<T>(
180180
export async function getCacheEntry(
181181
keys: string[],
182182
paths: string[],
183-
options?: CacheOptions
183+
options?: InternalCacheOptions
184184
): Promise<ArtifactCacheEntry | null> {
185185
const httpClient = createHttpClient()
186186
const version = getCacheVersion(paths, options?.compressionMethod)
@@ -258,7 +258,7 @@ export async function downloadCache(
258258
export async function reserveCache(
259259
key: string,
260260
paths: string[],
261-
options?: CacheOptions
261+
options?: InternalCacheOptions
262262
): Promise<number> {
263263
const httpClient = createHttpClient()
264264
const version = getCacheVersion(paths, options?.compressionMethod)

packages/cache/src/internal/contracts.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ export interface ReserveCacheResponse {
2020
cacheId: number
2121
}
2222

23-
export interface CacheOptions {
23+
export interface InternalCacheOptions {
2424
compressionMethod?: CompressionMethod
2525
}

0 commit comments

Comments
 (0)