mirror of
https://github.com/github/codeql-action.git
synced 2026-04-27 01:08:46 +00:00
Handle toolcache errors with StartProxyError
This commit is contained in:
Generated
+12
-1
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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");
|
||||
},
|
||||
);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user