Remove logCacheError function and implement inline 5xx error detection as requested
Co-authored-by: Link- <[email protected]>
This commit is contained in:
co-authored by
Link-
parent
bab3dcf7f3
commit
d48d6b62a4
Vendored
+41
-22
@@ -13,7 +13,6 @@ import {
|
|||||||
GetCacheEntryDownloadURLRequest
|
GetCacheEntryDownloadURLRequest
|
||||||
} from './generated/results/api/v1/cache'
|
} from './generated/results/api/v1/cache'
|
||||||
import {CacheFileSizeLimit} from './internal/constants'
|
import {CacheFileSizeLimit} from './internal/constants'
|
||||||
import {isServerErrorStatusCode} from './internal/requestUtils'
|
|
||||||
import {HttpClientError} from '@actions/http-client'
|
import {HttpClientError} from '@actions/http-client'
|
||||||
export class ValidationError extends Error {
|
export class ValidationError extends Error {
|
||||||
constructor(message: string) {
|
constructor(message: string) {
|
||||||
@@ -31,19 +30,6 @@ export class ReserveCacheError extends Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function logCacheError(message: string, error: Error): void {
|
|
||||||
// Log server errors (5xx) as errors, all other errors as warnings
|
|
||||||
if (
|
|
||||||
error instanceof HttpClientError &&
|
|
||||||
typeof error.statusCode === 'number' &&
|
|
||||||
isServerErrorStatusCode(error.statusCode)
|
|
||||||
) {
|
|
||||||
core.error(message)
|
|
||||||
} else {
|
|
||||||
core.warning(message)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkPaths(paths: string[]): void {
|
function checkPaths(paths: string[]): void {
|
||||||
if (!paths || paths.length === 0) {
|
if (!paths || paths.length === 0) {
|
||||||
throw new ValidationError(
|
throw new ValidationError(
|
||||||
@@ -215,7 +201,16 @@ async function restoreCacheV1(
|
|||||||
throw error
|
throw error
|
||||||
} else {
|
} else {
|
||||||
// warn on cache restore failure and continue build
|
// warn on cache restore failure and continue build
|
||||||
core.warning(`Failed to restore: ${(error as Error).message}`)
|
// Log server errors (5xx) as errors, all other errors as warnings
|
||||||
|
if (
|
||||||
|
typedError instanceof HttpClientError &&
|
||||||
|
typeof typedError.statusCode === 'number' &&
|
||||||
|
typedError.statusCode >= 500
|
||||||
|
) {
|
||||||
|
core.error(`Failed to restore: ${(error as Error).message}`)
|
||||||
|
} else {
|
||||||
|
core.warning(`Failed to restore: ${(error as Error).message}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
// Try to delete the archive to save space
|
// Try to delete the archive to save space
|
||||||
@@ -332,11 +327,17 @@ async function restoreCacheV2(
|
|||||||
if (typedError.name === ValidationError.name) {
|
if (typedError.name === ValidationError.name) {
|
||||||
throw error
|
throw error
|
||||||
} else {
|
} else {
|
||||||
// Log cache related errors
|
// Supress all non-validation cache related errors because caching should be optional
|
||||||
logCacheError(
|
// Log server errors (5xx) as errors, all other errors as warnings
|
||||||
`Failed to restore: ${(error as Error).message}`,
|
if (
|
||||||
typedError
|
typedError instanceof HttpClientError &&
|
||||||
)
|
typeof typedError.statusCode === 'number' &&
|
||||||
|
typedError.statusCode >= 500
|
||||||
|
) {
|
||||||
|
core.error(`Failed to restore: ${(error as Error).message}`)
|
||||||
|
} else {
|
||||||
|
core.warning(`Failed to restore: ${(error as Error).message}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
@@ -468,7 +469,16 @@ async function saveCacheV1(
|
|||||||
} else if (typedError.name === ReserveCacheError.name) {
|
} else if (typedError.name === ReserveCacheError.name) {
|
||||||
core.info(`Failed to save: ${typedError.message}`)
|
core.info(`Failed to save: ${typedError.message}`)
|
||||||
} else {
|
} else {
|
||||||
core.warning(`Failed to save: ${typedError.message}`)
|
// Log server errors (5xx) as errors, all other errors as warnings
|
||||||
|
if (
|
||||||
|
typedError instanceof HttpClientError &&
|
||||||
|
typeof typedError.statusCode === 'number' &&
|
||||||
|
typedError.statusCode >= 500
|
||||||
|
) {
|
||||||
|
core.error(`Failed to save: ${typedError.message}`)
|
||||||
|
} else {
|
||||||
|
core.warning(`Failed to save: ${typedError.message}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
// Try to delete the archive to save space
|
// Try to delete the archive to save space
|
||||||
@@ -607,7 +617,16 @@ async function saveCacheV2(
|
|||||||
} else if (typedError.name === ReserveCacheError.name) {
|
} else if (typedError.name === ReserveCacheError.name) {
|
||||||
core.info(`Failed to save: ${typedError.message}`)
|
core.info(`Failed to save: ${typedError.message}`)
|
||||||
} else {
|
} else {
|
||||||
logCacheError(`Failed to save: ${typedError.message}`, typedError)
|
// Log server errors (5xx) as errors, all other errors as warnings
|
||||||
|
if (
|
||||||
|
typedError instanceof HttpClientError &&
|
||||||
|
typeof typedError.statusCode === 'number' &&
|
||||||
|
typedError.statusCode >= 500
|
||||||
|
) {
|
||||||
|
core.error(`Failed to save: ${typedError.message}`)
|
||||||
|
} else {
|
||||||
|
core.warning(`Failed to save: ${typedError.message}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
// Try to delete the archive to save space
|
// Try to delete the archive to save space
|
||||||
|
|||||||
Reference in New Issue
Block a user