Move error checks out of getSarifFilePaths

This commit is contained in:
Michael B. Gale
2025-09-26 14:41:58 +01:00
parent 65925679a3
commit 022d7d5aa6
4 changed files with 56 additions and 45 deletions
+17 -12
View File
@@ -438,21 +438,11 @@ export function findSarifFilesInDir(
export function getSarifFilePaths(
sarifPath: string,
isSarif: (name: string) => boolean,
pathStats: fs.Stats,
) {
if (!fs.existsSync(sarifPath)) {
// This is always a configuration error, even for first-party runs.
throw new ConfigurationError(`Path does not exist: ${sarifPath}`);
}
let sarifFiles: string[];
if (fs.lstatSync(sarifPath).isDirectory()) {
if (pathStats.isDirectory()) {
sarifFiles = findSarifFilesInDir(sarifPath, isSarif);
if (sarifFiles.length === 0) {
// This is always a configuration error, even for first-party runs.
throw new ConfigurationError(
`No SARIF files found to upload in "${sarifPath}".`,
);
}
} else {
sarifFiles = [sarifPath];
}
@@ -623,11 +613,26 @@ export async function uploadFiles(
logger: Logger,
uploadTarget: analyses.AnalysisConfig,
): Promise<UploadResult> {
const pathStats = fs.lstatSync(inputSarifPath, { throwIfNoEntry: false });
if (pathStats === undefined) {
// This is always a configuration error, even for first-party runs.
throw new ConfigurationError(`Path does not exist: ${inputSarifPath}`);
}
const sarifPaths = getSarifFilePaths(
inputSarifPath,
uploadTarget.sarifPredicate,
pathStats,
);
if (sarifPaths.length === 0) {
// This is always a configuration error, even for first-party runs.
throw new ConfigurationError(
`No SARIF files found to upload in "${inputSarifPath}".`,
);
}
return uploadSpecifiedFiles(
sarifPaths,
checkoutPath,