Skip to content

Commit d061f2c

Browse files
committed
Handle CLI errors when creating debug artifacts
1 parent 5618c9f commit d061f2c

File tree

3 files changed

+82
-36
lines changed

3 files changed

+82
-36
lines changed

lib/debug-artifacts.js

Lines changed: 32 additions & 17 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: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
doesDirectoryExist,
1919
getCodeQLDatabasePath,
2020
listFolder,
21+
wrapError,
2122
} from "./util";
2223

2324
export function sanitizeArifactName(name: string): string {
@@ -65,34 +66,70 @@ export async function uploadCombinedSarifArtifacts() {
6566
}
6667
}
6768

68-
export async function uploadAllAvailableDebugArtifacts(
69+
function tryGetSarifResultPath(
6970
config: Config,
71+
language: Language,
7072
logger: Logger,
71-
) {
72-
const filesToUpload: string[] = [];
73-
74-
const analyzeActionOutputDir = process.env[EnvVar.SARIF_RESULTS_OUTPUT_DIR];
75-
for (const lang of config.languages) {
76-
// Add any SARIF files, if they exist
73+
): string[] {
74+
try {
75+
const analyzeActionOutputDir = process.env[EnvVar.SARIF_RESULTS_OUTPUT_DIR];
7776
if (
7877
analyzeActionOutputDir !== undefined &&
7978
fs.existsSync(analyzeActionOutputDir) &&
8079
fs.lstatSync(analyzeActionOutputDir).isDirectory()
8180
) {
82-
const sarifFile = path.resolve(analyzeActionOutputDir, `${lang}.sarif`);
81+
const sarifFile = path.resolve(
82+
analyzeActionOutputDir,
83+
`${language}.sarif`,
84+
);
8385
// Move SARIF to DB location so that they can be uploaded with the same root directory as the other artifacts.
8486
if (fs.existsSync(sarifFile)) {
8587
const sarifInDbLocation = path.resolve(
8688
config.dbLocation,
87-
`${lang}.sarif`,
89+
`${language}.sarif`,
8890
);
8991
fs.copyFileSync(sarifFile, sarifInDbLocation);
90-
filesToUpload.push(sarifInDbLocation);
92+
return [sarifInDbLocation];
9193
}
9294
}
95+
} catch (e) {
96+
logger.warning(
97+
`Failed to find SARIF results path for ${language}. ${wrapError(e)}`,
98+
);
99+
}
100+
return [];
101+
}
102+
103+
async function tryBundleDatabase(
104+
config: Config,
105+
language: Language,
106+
logger: Logger,
107+
): Promise<string[]> {
108+
try {
109+
if (!dbIsFinalized(config, language, logger)) {
110+
return [await createPartialDatabaseBundle(config, language)];
111+
} else {
112+
return [await createDatabaseBundleCli(config, language)];
113+
}
114+
} catch (e) {
115+
logger.warning(
116+
`Failed to bundle database for ${language}. ${wrapError(e)}`,
117+
);
118+
return [];
119+
}
120+
}
121+
122+
export async function uploadAllAvailableDebugArtifacts(
123+
config: Config,
124+
logger: Logger,
125+
) {
126+
const filesToUpload: string[] = [];
127+
128+
for (const language of config.languages) {
129+
filesToUpload.push(...tryGetSarifResultPath(config, language, logger));
93130

94131
// Add any log files
95-
const databaseDirectory = getCodeQLDatabasePath(config, lang);
132+
const databaseDirectory = getCodeQLDatabasePath(config, language);
96133
const logsDirectory = path.resolve(databaseDirectory, "log");
97134
if (doesDirectoryExist(logsDirectory)) {
98135
filesToUpload.push(...listFolder(logsDirectory));
@@ -108,13 +145,7 @@ export async function uploadAllAvailableDebugArtifacts(
108145
}
109146

110147
// Add database bundle
111-
let databaseBundlePath: string;
112-
if (!dbIsFinalized(config, lang, logger)) {
113-
databaseBundlePath = await createPartialDatabaseBundle(config, lang);
114-
} else {
115-
databaseBundlePath = await createDatabaseBundleCli(config, lang);
116-
}
117-
filesToUpload.push(databaseBundlePath);
148+
filesToUpload.push(...(await tryBundleDatabase(config, language, logger)));
118149
}
119150

120151
await uploadDebugArtifacts(

0 commit comments

Comments
 (0)