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);
}

File diff suppressed because one or more lines are too long

View file

@ -67,15 +67,15 @@ export 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(
function tryPrepareSarifDebugArtifact(
config: Config,
language: Language,
logger: Logger,
): string[] {
): string | undefined {
try {
const analyzeActionOutputDir = process.env[EnvVar.SARIF_RESULTS_OUTPUT_DIR];
if (
@ -94,7 +94,7 @@ function tryGetSarifResultPath(
`${language}.sarif`,
);
fs.copyFileSync(sarifFile, sarifInDbLocation);
return [sarifInDbLocation];
return sarifInDbLocation;
}
}
} catch (e) {
@ -104,24 +104,23 @@ function tryGetSarifResultPath(
)}`,
);
}
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: Config,
language: Language,
logger: Logger,
): Promise<string[]> {
): Promise<string | undefined> {
try {
if (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. ` +
@ -129,14 +128,14 @@ async function tryBundleDatabase(
);
}
}
return [await createPartialDatabaseBundle(config, language)];
return await createPartialDatabaseBundle(config, language);
} catch (e) {
logger.warning(
`Failed to bundle database for ${language}. Reason: ${getErrorMessage(
e,
)}`,
);
return [];
return undefined;
}
}
@ -153,7 +152,14 @@ export async function tryUploadAllAvailableDebugArtifacts(
const filesToUpload: string[] = [];
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 = getCodeQLDatabasePath(config, language);
@ -172,9 +178,10 @@ export async function tryUploadAllAvailableDebugArtifacts(
}
// Add database bundle
filesToUpload.push(
...(await tryBundleDatabase(config, language, logger)),
);
const databaseBundle = await tryBundleDatabase(config, language, logger);
if (databaseBundle) {
filesToUpload.push(databaseBundle);
}
}
await uploadDebugArtifacts(