diff --git a/packages/cmd/src/services/cache/get.ts b/packages/cmd/src/services/cache/get.ts index 1990e15..a960212 100644 --- a/packages/cmd/src/services/cache/get.ts +++ b/packages/cmd/src/services/cache/get.ts @@ -4,61 +4,58 @@ import { retrieveCache } from '../../api'; import { PRESETS } from '../../commands/cache/options'; import { getCacheCommandConfig } from '../../config/cache'; import { getCI } from '../../env/ciProvider'; -import { warnWithNoTrace } from '../../logger'; import { unzipBuffer } from './fs'; -import { MetaFile, warn } from './lib'; +import { MetaFile } from './lib'; import { download } from './network'; import { handlePostLastRunPreset, handlePreLastRunPreset } from './presets'; export async function handleGetCache() { - try { - const config = getCacheCommandConfig(); - if (config.type !== 'GET_COMMAND_CONFIG' || !config.values) { - throw new Error('Config is missing!'); - } - - const { recordKey, id, preset, matrixIndex, matrixTotal } = config.values; - const outputDir = config.values.outputDir; + const config = getCacheCommandConfig(); + if (config.type !== 'GET_COMMAND_CONFIG' || !config.values) { + throw new Error('Config is missing!'); + } - const ci = getCI(); + const { recordKey, id, preset, matrixIndex, matrixTotal } = config.values; + const outputDir = config.values.outputDir; - if (preset === PRESETS.lastRun) { - await handlePreLastRunPreset(config.values, ci); - } + const ci = getCI(); - const result = await retrieveCache({ - recordKey, - ci, - id, - config: { - matrixIndex, - matrixTotal, - }, - }); + if (preset === PRESETS.lastRun) { + await handlePreLastRunPreset(config.values, ci); + } - try { - await handleArchiveDownload({ - readUrl: result.readUrl, - outputDir, - }); + const result = await retrieveCache({ + recordKey, + ci, + id, + config: { + matrixIndex, + matrixTotal, + }, + }); - const meta = await handleMetaDownload(result.metaReadUrl); + try { + await handleArchiveDownload({ + readUrl: result.readUrl, + outputDir, + }); - if (preset === PRESETS.lastRun) { - await handlePostLastRunPreset(config.values, ci, meta); - } - } catch (e) { - if (isAxiosError(e)) { - if (e.response?.status && e.response?.status < 500) { - warnWithNoTrace(`Cache with ID "${result.cacheId}" not found`); - return; - } - } + const meta = await handleMetaDownload(result.metaReadUrl); - throw e; + if (preset === PRESETS.lastRun) { + await handlePostLastRunPreset(config.values, ci, meta); } } catch (e) { - warn(e, 'Failed to obtain cache'); + if (isAxiosError(e)) { + if ( + e.response?.status && + (e.response?.status === 403 || e.response?.status === 404) + ) { + throw new Error(`Cache with ID "${result.cacheId}" not found`); + } + } + + throw e; } } diff --git a/packages/cmd/src/services/cache/set.ts b/packages/cmd/src/services/cache/set.ts index 7fa3ee1..f027c53 100644 --- a/packages/cmd/src/services/cache/set.ts +++ b/packages/cmd/src/services/cache/set.ts @@ -4,7 +4,7 @@ import { PRESETS } from '../../commands/cache/options'; import { getCacheCommandConfig } from '../../config/cache'; import { getCI } from '../../env/ciProvider'; import { filterPaths, zipFilesToBuffer } from './fs'; -import { createMeta, getLastRunFilePath, warn } from './lib'; +import { createMeta, getLastRunFilePath } from './lib'; import { ContentType, getDefautUploadProgressHandler, @@ -12,64 +12,60 @@ import { } from './network'; export async function handleSetCache() { - try { - const config = getCacheCommandConfig(); - if (config.type !== 'SET_COMMAND_CONFIG' || !config.values) { - throw new Error('Config is missing!'); - } + const config = getCacheCommandConfig(); + if (config.type !== 'SET_COMMAND_CONFIG' || !config.values) { + throw new Error('Config is missing!'); + } - const { recordKey, id, preset, pwOutputDir, matrixIndex, matrixTotal } = - config.values; + const { recordKey, id, preset, pwOutputDir, matrixIndex, matrixTotal } = + config.values; - const paths = config.values.paths ? filterPaths(config.values.paths) : []; + const paths = config.values.paths ? filterPaths(config.values.paths) : []; - const uploadPaths: string[] = []; + const uploadPaths: string[] = []; - if (paths && paths.length > 0) { - uploadPaths.push(...paths); - } + if (paths && paths.length > 0) { + uploadPaths.push(...paths); + } - const ci = getCI(); + const ci = getCI(); - if (preset === PRESETS.lastRun) { - const lastRunPath = getLastRunFilePath(pwOutputDir); - uploadPaths.push(lastRunPath); - } + if (preset === PRESETS.lastRun) { + const lastRunPath = getLastRunFilePath(pwOutputDir); + uploadPaths.push(lastRunPath); + } - if (uploadPaths.length === 0) { - throw new Error('No paths available to upload'); - } + if (uploadPaths.length === 0) { + throw new Error('No paths available to upload'); + } - const result = await createCache({ - recordKey, - ci, - id, - config: { - matrixIndex, - matrixTotal, - }, - }); + const result = await createCache({ + recordKey, + ci, + id, + config: { + matrixIndex, + matrixTotal, + }, + }); - await handleArchiveUpload({ - archive: await zipFilesToBuffer(uploadPaths), - cacheId: result.cacheId, - uploadUrl: result.uploadUrl, - }); + await handleArchiveUpload({ + archive: await zipFilesToBuffer(uploadPaths), + cacheId: result.cacheId, + uploadUrl: result.uploadUrl, + }); - await handleMetaUpload({ - meta: createMeta({ - cacheId: result.cacheId, - config: config.values, - ci, - orgId: result.orgId, - paths: uploadPaths, - }), + await handleMetaUpload({ + meta: createMeta({ cacheId: result.cacheId, - uploadUrl: result.metaUploadUrl, - }); - } catch (e) { - warn(e, 'Failed to save cache'); - } + config: config.values, + ci, + orgId: result.orgId, + paths: uploadPaths, + }), + cacheId: result.cacheId, + uploadUrl: result.metaUploadUrl, + }); } async function handleArchiveUpload({