Skip to content

Commit

Permalink
Revert "try reverting error handling to fix tests"
Browse files Browse the repository at this point in the history
This reverts commit 751d4d0.
  • Loading branch information
Nava2 committed Jan 9, 2025
1 parent 8028bcd commit 7049568
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
24 changes: 12 additions & 12 deletions sources/src/actions/github-actions-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as core from '@actions/core'
import * as ghCache from '@actions/cache'
import * as ghExec from '@actions/exec'

import {cache, GradleEnvCacheEntry} from '../env/cache'
import {cache, CacheEntryAlreadyExistsError, CacheValidationError, GradleEnvCacheEntry} from '../env/cache'
import {exec, GradleEnvExecOptions} from '../env/execution'
import {log, LogLevel} from '../env/logging'
import {state} from '../env/state'
Expand Down Expand Up @@ -69,17 +69,17 @@ function setupCache(): void {
isAvailable: ghCache.isFeatureAvailable,

saveCache: async (paths: string[], key: string): Promise<GradleEnvCacheEntry> => {
// try {
return await ghCache.saveCache(paths, key)
// } catch (error) {
// if (error instanceof ghCache.ReserveCacheError) {
// throw new CacheEntryAlreadyExistsError(error.message)
// } else if (error instanceof ghCache.ValidationError) {
// throw new CacheValidationError(error.message)
// } else {
// throw error
// }
// }
try {
return await ghCache.saveCache(paths, key)
} catch (error) {
if (error instanceof ghCache.ReserveCacheError) {
throw new CacheEntryAlreadyExistsError(error.message)
} else if (error instanceof ghCache.ValidationError) {
throw new CacheValidationError(error.message)
} else {
throw error
}
}
},

restoreCache: ghCache.restoreCache
Expand Down
11 changes: 5 additions & 6 deletions sources/src/caching/cache-utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as ghCache from '@actions/cache'
import * as crypto from 'crypto'
import * as path from 'path'
import * as fs from 'fs'

import {cache, GradleEnvCacheEntry, RemoteCacheDownloadOptions} from '../env/cache'
import {cache, CacheEntryAlreadyExistsError, CacheValidationError, GradleEnvCacheEntry} from '../env/cache'
import {exec} from '../env/execution'
import {log} from '../env/logging'
import {CacheEntryListener} from './cache-reporting'
Expand Down Expand Up @@ -33,7 +32,7 @@ export async function restoreCache(
try {
const startTime = Date.now()
// Only override the read timeout if the SEGMENT_DOWNLOAD_TIMEOUT_MINS env var has NOT been set
const cacheRestoreOptions: RemoteCacheDownloadOptions = process.env[SEGMENT_DOWNLOAD_TIMEOUT_VAR]
const cacheRestoreOptions = process.env[SEGMENT_DOWNLOAD_TIMEOUT_VAR]
? {}
: {segmentTimeoutInMs: SEGMENT_DOWNLOAD_TIMEOUT_DEFAULT}
const restoredEntry = await cache.restoreCache(cachePath, cacheKey, cacheRestoreKeys, cacheRestoreOptions)
Expand All @@ -58,7 +57,7 @@ export async function saveCache(cachePath: string[], cacheKey: string, listener:
listener.markSaved(savedEntry.key, savedEntry.size, saveTime)
log.info(`Saved cache entry with key ${cacheKey} from ${cachePath.join()} in ${saveTime}ms`)
} catch (error) {
if (error instanceof ghCache.ReserveCacheError) {
if (error instanceof CacheEntryAlreadyExistsError) {
listener.markAlreadyExists(cacheKey)
} else {
listener.markNotSaved((error as Error).message)
Expand All @@ -68,11 +67,11 @@ export async function saveCache(cachePath: string[], cacheKey: string, listener:
}

export function handleCacheFailure(error: unknown, message: string): void {
if (error instanceof ghCache.ValidationError) {
if (error instanceof CacheValidationError) {
// Fail on cache validation errors
throw error
}
if (error instanceof ghCache.ReserveCacheError) {
if (error instanceof CacheEntryAlreadyExistsError) {
// Reserve cache errors are expected if the artifact has been previously cached
log.info(`${message}: ${error}`)
} else {
Expand Down

0 comments on commit 7049568

Please sign in to comment.