Change behavior of the exception throwing

This commit is contained in:
Ivan Zosimov 2022-04-20 16:43:06 +02:00
parent c64d0e04b0
commit 8c8442b8f8
5 changed files with 52 additions and 37 deletions

View file

@ -33,16 +33,23 @@ const cachePackages = async () => {
const packageManagerInfo = await getPackageManagerInfo(packageManager);
const cachePath = await getCacheDirectoryPath(packageManagerInfo);
const cachePaths = await getCacheDirectoryPath(packageManagerInfo);
for (let path of cachePath) {
let pathsCounter = cachePaths.length;
for (let path of cachePaths) {
if (!fs.existsSync(path)) {
throw new Error(
logWarning(
`Cache folder path is retrieved but doesn't exist on disk: ${path}`
);
pathsCounter--;
}
}
if (!pathsCounter) {
throw `Cache folder paths are retrieved but don't exist on disk`;
}
if (primaryKey === state) {
core.info(
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
@ -51,7 +58,7 @@ const cachePackages = async () => {
}
try {
await cache.saveCache(cachePath, primaryKey);
await cache.saveCache(cachePaths, primaryKey);
core.info(`Cache saved with the key: ${primaryKey}`);
} catch (error) {
if (error.name === cache.ValidationError.name) {
@ -64,4 +71,9 @@ const cachePackages = async () => {
}
};
export function logWarning(message: string): void {
const warningPrefix = '[warning]';
core.info(`${warningPrefix}${message}`);
}
run();