Handle toolcache errors with StartProxyError

This commit is contained in:
Michael B. Gale
2026-01-29 14:16:36 +00:00
parent 1d0f911837
commit 28f6d316c0
4 changed files with 67 additions and 2 deletions
+12 -1
View File
@@ -119796,6 +119796,16 @@ async function extractProxy(logger, archive) {
throw new StartProxyError("Failed to extract proxy archive." /* ExtractionFailed */);
}
}
async function cacheProxy(logger, path2, filename, version) {
try {
return await toolcache.cacheDir(path2, filename, version);
} catch (error3) {
logger.error(
`Failed to add proxy archive from ${path2} to toolcache: ${getErrorMessage(error3)}`
);
throw new StartProxyError("Failed to add proxy to toolcache" /* CacheFailed */);
}
}
// src/start-proxy-action.ts
var KEY_SIZE = 2048;
@@ -119960,7 +119970,8 @@ async function getProxyBinaryPath(logger) {
);
const temp = await downloadProxy(logger, proxyInfo.url, authorization);
const extracted = await extractProxy(logger, temp);
proxyBin = await toolcache2.cacheDir(
proxyBin = await cacheProxy(
logger,
extracted,
proxyFileName,
proxyInfo.version
+3 -1
View File
@@ -10,6 +10,7 @@ import { getApiDetails, getAuthorizationHeaderFor } from "./api-client";
import { KnownLanguage } from "./languages";
import { getActionsLogger, Logger } from "./logging";
import {
cacheProxy,
Credential,
credentialToStr,
downloadProxy,
@@ -242,7 +243,8 @@ async function getProxyBinaryPath(logger: Logger): Promise<string> {
);
const temp = await downloadProxy(logger, proxyInfo.url, authorization);
const extracted = await extractProxy(logger, temp);
proxyBin = await toolcache.cacheDir(
proxyBin = await cacheProxy(
logger,
extracted,
proxyFileName,
proxyInfo.version,
+26
View File
@@ -447,3 +447,29 @@ test(
await startProxyExports.extractProxy(logger, "path");
},
);
test("cacheProxy - returns file path on success", async (t) => {
await withRecordingLoggerAsync(async (logger) => {
const testPath = "/some/path";
sinon.stub(toolcache, "cacheDir").resolves(testPath);
const result = await startProxyExports.cacheProxy(
logger,
"/other/path",
"proxy",
"1.0",
);
t.is(result, testPath);
});
});
test(
"cacheProxy",
wrapFailureTest,
() => {
sinon.stub(toolcache, "cacheDir").throws();
},
async (logger) => {
await startProxyExports.cacheProxy(logger, "/other/path", "proxy", "1.0");
},
);
+26
View File
@@ -24,6 +24,7 @@ import { ConfigurationError, getErrorMessage, isDefined } from "./util";
export enum StartProxyErrorType {
DownloadFailed = "Failed to download proxy archive.",
ExtractionFailed = "Failed to extract proxy archive.",
CacheFailed = "Failed to add proxy to toolcache",
}
/**
@@ -453,3 +454,28 @@ export async function extractProxy(logger: Logger, archive: string) {
throw new StartProxyError(StartProxyErrorType.ExtractionFailed);
}
}
/**
* Attempts to store the proxy in the toolcache.
*
* @param logger The logger to use.
* @param path The source path to add to the toolcache.
* @param filename The filename of the proxy binary.
* @param version The version of the proxy.
* @returns The path to the directory in the toolcache.
*/
export async function cacheProxy(
logger: Logger,
path: string,
filename: string,
version: string,
) {
try {
return await toolcache.cacheDir(path, filename, version);
} catch (error) {
logger.error(
`Failed to add proxy archive from ${path} to toolcache: ${getErrorMessage(error)}`,
);
throw new StartProxyError(StartProxyErrorType.CacheFailed);
}
}