Improve docs and method naming

This commit is contained in:
Henry Mercer 2024-09-17 10:58:00 +02:00
parent 782de45248
commit 78d398ebc6
3 changed files with 43 additions and 31 deletions

31
lib/debug-artifacts.js generated
View file

@ -72,11 +72,11 @@ async function uploadCombinedSarifArtifacts() {
}
}
/**
* Try to get the SARIF result path for the given language.
* Try to prepare a SARIF result debug artifact for the given language.
*
* If an error occurs, log it and return an empty list.
* @return The path to that debug artifact, or undefined if an error occurs.
*/
function tryGetSarifResultPath(config, language, logger) {
function tryPrepareSarifDebugArtifact(config, language, logger) {
try {
const analyzeActionOutputDir = process.env[environment_1.EnvVar.SARIF_RESULTS_OUTPUT_DIR];
if (analyzeActionOutputDir !== undefined &&
@ -87,37 +87,36 @@ function tryGetSarifResultPath(config, language, logger) {
if (fs.existsSync(sarifFile)) {
const sarifInDbLocation = path.resolve(config.dbLocation, `${language}.sarif`);
fs.copyFileSync(sarifFile, sarifInDbLocation);
return [sarifInDbLocation];
return sarifInDbLocation;
}
}
}
catch (e) {
logger.warning(`Failed to find SARIF results path for ${language}. Reason: ${(0, util_1.getErrorMessage)(e)}`);
}
return [];
return undefined;
}
/**
* Try to bundle the database for the given language. Return a list containing
* the path to the database bundle.
* Try to bundle the database for the given language.
*
* If an error occurs, log it and return an empty list.
* @return The path to the database bundle, or undefined if an error occurs.
*/
async function tryBundleDatabase(config, language, logger) {
try {
if ((0, analyze_1.dbIsFinalized)(config, language, logger)) {
try {
return [await createDatabaseBundleCli(config, language)];
return await createDatabaseBundleCli(config, language);
}
catch (e) {
logger.warning(`Failed to bundle database for ${language} using the CLI. ` +
`Falling back to a partial bundle. Reason: ${(0, util_1.getErrorMessage)(e)}`);
}
}
return [await createPartialDatabaseBundle(config, language)];
return await createPartialDatabaseBundle(config, language);
}
catch (e) {
logger.warning(`Failed to bundle database for ${language}. Reason: ${(0, util_1.getErrorMessage)(e)}`);
return [];
return undefined;
}
}
/**
@ -129,7 +128,10 @@ async function tryUploadAllAvailableDebugArtifacts(config, logger) {
try {
const filesToUpload = [];
for (const language of config.languages) {
filesToUpload.push(...tryGetSarifResultPath(config, language, logger));
const sarifResultDebugArtifact = tryPrepareSarifDebugArtifact(config, language, logger);
if (sarifResultDebugArtifact) {
filesToUpload.push(sarifResultDebugArtifact);
}
// Add any log files
const databaseDirectory = (0, util_1.getCodeQLDatabasePath)(config, language);
const logsDirectory = path.resolve(databaseDirectory, "log");
@ -142,7 +144,10 @@ async function tryUploadAllAvailableDebugArtifacts(config, logger) {
filesToUpload.push(...(0, util_1.listFolder)(multiLanguageTracingLogsDirectory));
}
// Add database bundle
filesToUpload.push(...(await tryBundleDatabase(config, language, logger)));
const databaseBundle = await tryBundleDatabase(config, language, logger);
if (databaseBundle) {
filesToUpload.push(databaseBundle);
}
}
await uploadDebugArtifacts(filesToUpload, config.dbLocation, config.debugArtifactName);
}