Skip to content

Commit 1d0f911

Browse files
committed
Handle extraction errors with StartProxyError
1 parent 05bd050 commit 1d0f911

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

lib/start-proxy-action.js

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/start-proxy-action.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
Credential,
1414
credentialToStr,
1515
downloadProxy,
16+
extractProxy,
1617
getCredentials,
1718
getDownloadUrl,
1819
parseLanguage,
@@ -240,7 +241,7 @@ async function getProxyBinaryPath(logger: Logger): Promise<string> {
240241
proxyInfo.url,
241242
);
242243
const temp = await downloadProxy(logger, proxyInfo.url, authorization);
243-
const extracted = await toolcache.extractTar(temp);
244+
const extracted = await extractProxy(logger, temp);
244245
proxyBin = await toolcache.cacheDir(
245246
extracted,
246247
proxyFileName,

src/start-proxy.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,3 +426,24 @@ test(
426426
await startProxyExports.downloadProxy(logger, "url", undefined);
427427
},
428428
);
429+
430+
test("extractProxy - returns file path on success", async (t) => {
431+
await withRecordingLoggerAsync(async (logger) => {
432+
const testPath = "/some/path";
433+
sinon.stub(toolcache, "extractTar").resolves(testPath);
434+
435+
const result = await startProxyExports.extractProxy(logger, "/other/path");
436+
t.is(result, testPath);
437+
});
438+
});
439+
440+
test(
441+
"extractProxy",
442+
wrapFailureTest,
443+
() => {
444+
sinon.stub(toolcache, "extractTar").throws();
445+
},
446+
async (logger) => {
447+
await startProxyExports.extractProxy(logger, "path");
448+
},
449+
);

src/start-proxy.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { ConfigurationError, getErrorMessage, isDefined } from "./util";
2323
*/
2424
export enum StartProxyErrorType {
2525
DownloadFailed = "Failed to download proxy archive.",
26+
ExtractionFailed = "Failed to extract proxy archive.",
2627
}
2728

2829
/**
@@ -413,7 +414,7 @@ export function credentialToStr(c: Credential): string {
413414
/**
414415
* Attempts to download a file from `url` into the toolcache.
415416
*
416-
* @param logger THe logger to use.
417+
* @param logger The logger to use.
417418
* @param url The URL to download the proxy binary from.
418419
* @param authorization The authorization information to use.
419420
* @returns If successful, the path to the downloaded file.
@@ -434,3 +435,21 @@ export async function downloadProxy(
434435
throw new StartProxyError(StartProxyErrorType.DownloadFailed);
435436
}
436437
}
438+
439+
/**
440+
* Attempts to extract the proxy binary from the `archive`.
441+
*
442+
* @param logger The logger to use.
443+
* @param archive The archive to extract.
444+
* @returns The path to the extracted file(s).
445+
*/
446+
export async function extractProxy(logger: Logger, archive: string) {
447+
try {
448+
return await toolcache.extractTar(archive);
449+
} catch (error) {
450+
logger.error(
451+
`Failed to extract proxy archive from ${archive}: ${getErrorMessage(error)}`,
452+
);
453+
throw new StartProxyError(StartProxyErrorType.ExtractionFailed);
454+
}
455+
}

0 commit comments

Comments
 (0)