Skip to content

Commit 78d398e

Browse files
committed
Improve docs and method naming
1 parent 782de45 commit 78d398e

File tree

3 files changed

+43
-31
lines changed

3 files changed

+43
-31
lines changed

lib/debug-artifacts.js

Lines changed: 18 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/debug-artifacts.js.map

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

src/debug-artifacts.ts

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ export async function uploadCombinedSarifArtifacts() {
6767
}
6868

6969
/**
70-
* Try to get the SARIF result path for the given language.
70+
* Try to prepare a SARIF result debug artifact for the given language.
7171
*
72-
* If an error occurs, log it and return an empty list.
72+
* @return The path to that debug artifact, or undefined if an error occurs.
7373
*/
74-
function tryGetSarifResultPath(
74+
function tryPrepareSarifDebugArtifact(
7575
config: Config,
7676
language: Language,
7777
logger: Logger,
78-
): string[] {
78+
): string | undefined {
7979
try {
8080
const analyzeActionOutputDir = process.env[EnvVar.SARIF_RESULTS_OUTPUT_DIR];
8181
if (
@@ -94,7 +94,7 @@ function tryGetSarifResultPath(
9494
`${language}.sarif`,
9595
);
9696
fs.copyFileSync(sarifFile, sarifInDbLocation);
97-
return [sarifInDbLocation];
97+
return sarifInDbLocation;
9898
}
9999
}
100100
} catch (e) {
@@ -104,39 +104,38 @@ function tryGetSarifResultPath(
104104
)}`,
105105
);
106106
}
107-
return [];
107+
return undefined;
108108
}
109109

110110
/**
111-
* Try to bundle the database for the given language. Return a list containing
112-
* the path to the database bundle.
111+
* Try to bundle the database for the given language.
113112
*
114-
* If an error occurs, log it and return an empty list.
113+
* @return The path to the database bundle, or undefined if an error occurs.
115114
*/
116115
async function tryBundleDatabase(
117116
config: Config,
118117
language: Language,
119118
logger: Logger,
120-
): Promise<string[]> {
119+
): Promise<string | undefined> {
121120
try {
122121
if (dbIsFinalized(config, language, logger)) {
123122
try {
124-
return [await createDatabaseBundleCli(config, language)];
123+
return await createDatabaseBundleCli(config, language);
125124
} catch (e) {
126125
logger.warning(
127126
`Failed to bundle database for ${language} using the CLI. ` +
128127
`Falling back to a partial bundle. Reason: ${getErrorMessage(e)}`,
129128
);
130129
}
131130
}
132-
return [await createPartialDatabaseBundle(config, language)];
131+
return await createPartialDatabaseBundle(config, language);
133132
} catch (e) {
134133
logger.warning(
135134
`Failed to bundle database for ${language}. Reason: ${getErrorMessage(
136135
e,
137136
)}`,
138137
);
139-
return [];
138+
return undefined;
140139
}
141140
}
142141

@@ -153,7 +152,14 @@ export async function tryUploadAllAvailableDebugArtifacts(
153152
const filesToUpload: string[] = [];
154153

155154
for (const language of config.languages) {
156-
filesToUpload.push(...tryGetSarifResultPath(config, language, logger));
155+
const sarifResultDebugArtifact = tryPrepareSarifDebugArtifact(
156+
config,
157+
language,
158+
logger,
159+
);
160+
if (sarifResultDebugArtifact) {
161+
filesToUpload.push(sarifResultDebugArtifact);
162+
}
157163

158164
// Add any log files
159165
const databaseDirectory = getCodeQLDatabasePath(config, language);
@@ -172,9 +178,10 @@ export async function tryUploadAllAvailableDebugArtifacts(
172178
}
173179

174180
// Add database bundle
175-
filesToUpload.push(
176-
...(await tryBundleDatabase(config, language, logger)),
177-
);
181+
const databaseBundle = await tryBundleDatabase(config, language, logger);
182+
if (databaseBundle) {
183+
filesToUpload.push(databaseBundle);
184+
}
178185
}
179186

180187
await uploadDebugArtifacts(

0 commit comments

Comments
 (0)