Handle extraction errors with StartProxyError

This commit is contained in:
Michael B. Gale
2026-01-29 13:45:46 +00:00
parent 05bd050f34
commit 1d0f911837
4 changed files with 54 additions and 3 deletions
+11 -1
View File
@@ -119786,6 +119786,16 @@ async function downloadProxy(logger, url, authorization) {
throw new StartProxyError("Failed to download proxy archive." /* DownloadFailed */);
}
}
async function extractProxy(logger, archive) {
try {
return await toolcache.extractTar(archive);
} catch (error3) {
logger.error(
`Failed to extract proxy archive from ${archive}: ${getErrorMessage(error3)}`
);
throw new StartProxyError("Failed to extract proxy archive." /* ExtractionFailed */);
}
}
// src/start-proxy-action.ts
var KEY_SIZE = 2048;
@@ -119949,7 +119959,7 @@ async function getProxyBinaryPath(logger) {
proxyInfo.url
);
const temp = await downloadProxy(logger, proxyInfo.url, authorization);
const extracted = await toolcache2.extractTar(temp);
const extracted = await extractProxy(logger, temp);
proxyBin = await toolcache2.cacheDir(
extracted,
proxyFileName,
+2 -1
View File
@@ -13,6 +13,7 @@ import {
Credential,
credentialToStr,
downloadProxy,
extractProxy,
getCredentials,
getDownloadUrl,
parseLanguage,
@@ -240,7 +241,7 @@ async function getProxyBinaryPath(logger: Logger): Promise<string> {
proxyInfo.url,
);
const temp = await downloadProxy(logger, proxyInfo.url, authorization);
const extracted = await toolcache.extractTar(temp);
const extracted = await extractProxy(logger, temp);
proxyBin = await toolcache.cacheDir(
extracted,
proxyFileName,
+21
View File
@@ -426,3 +426,24 @@ test(
await startProxyExports.downloadProxy(logger, "url", undefined);
},
);
test("extractProxy - returns file path on success", async (t) => {
await withRecordingLoggerAsync(async (logger) => {
const testPath = "/some/path";
sinon.stub(toolcache, "extractTar").resolves(testPath);
const result = await startProxyExports.extractProxy(logger, "/other/path");
t.is(result, testPath);
});
});
test(
"extractProxy",
wrapFailureTest,
() => {
sinon.stub(toolcache, "extractTar").throws();
},
async (logger) => {
await startProxyExports.extractProxy(logger, "path");
},
);
+20 -1
View File
@@ -23,6 +23,7 @@ import { ConfigurationError, getErrorMessage, isDefined } from "./util";
*/
export enum StartProxyErrorType {
DownloadFailed = "Failed to download proxy archive.",
ExtractionFailed = "Failed to extract proxy archive.",
}
/**
@@ -413,7 +414,7 @@ export function credentialToStr(c: Credential): string {
/**
* Attempts to download a file from `url` into the toolcache.
*
* @param logger THe logger to use.
* @param logger The logger to use.
* @param url The URL to download the proxy binary from.
* @param authorization The authorization information to use.
* @returns If successful, the path to the downloaded file.
@@ -434,3 +435,21 @@ export async function downloadProxy(
throw new StartProxyError(StartProxyErrorType.DownloadFailed);
}
}
/**
* Attempts to extract the proxy binary from the `archive`.
*
* @param logger The logger to use.
* @param archive The archive to extract.
* @returns The path to the extracted file(s).
*/
export async function extractProxy(logger: Logger, archive: string) {
try {
return await toolcache.extractTar(archive);
} catch (error) {
logger.error(
`Failed to extract proxy archive from ${archive}: ${getErrorMessage(error)}`,
);
throw new StartProxyError(StartProxyErrorType.ExtractionFailed);
}
}