Skip to content

Commit 022d7d5

Browse files
committed
Move error checks out of getSarifFilePaths
1 parent 6592567 commit 022d7d5

File tree

4 files changed

+56
-45
lines changed

4 files changed

+56
-45
lines changed

lib/analyze-action.js

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

lib/init-action-post.js

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

lib/upload-lib.js

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

src/upload-lib.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -438,21 +438,11 @@ export function findSarifFilesInDir(
438438
export function getSarifFilePaths(
439439
sarifPath: string,
440440
isSarif: (name: string) => boolean,
441+
pathStats: fs.Stats,
441442
) {
442-
if (!fs.existsSync(sarifPath)) {
443-
// This is always a configuration error, even for first-party runs.
444-
throw new ConfigurationError(`Path does not exist: ${sarifPath}`);
445-
}
446-
447443
let sarifFiles: string[];
448-
if (fs.lstatSync(sarifPath).isDirectory()) {
444+
if (pathStats.isDirectory()) {
449445
sarifFiles = findSarifFilesInDir(sarifPath, isSarif);
450-
if (sarifFiles.length === 0) {
451-
// This is always a configuration error, even for first-party runs.
452-
throw new ConfigurationError(
453-
`No SARIF files found to upload in "${sarifPath}".`,
454-
);
455-
}
456446
} else {
457447
sarifFiles = [sarifPath];
458448
}
@@ -623,11 +613,26 @@ export async function uploadFiles(
623613
logger: Logger,
624614
uploadTarget: analyses.AnalysisConfig,
625615
): Promise<UploadResult> {
616+
const pathStats = fs.lstatSync(inputSarifPath, { throwIfNoEntry: false });
617+
618+
if (pathStats === undefined) {
619+
// This is always a configuration error, even for first-party runs.
620+
throw new ConfigurationError(`Path does not exist: ${inputSarifPath}`);
621+
}
622+
626623
const sarifPaths = getSarifFilePaths(
627624
inputSarifPath,
628625
uploadTarget.sarifPredicate,
626+
pathStats,
629627
);
630628

629+
if (sarifPaths.length === 0) {
630+
// This is always a configuration error, even for first-party runs.
631+
throw new ConfigurationError(
632+
`No SARIF files found to upload in "${inputSarifPath}".`,
633+
);
634+
}
635+
631636
return uploadSpecifiedFiles(
632637
sarifPaths,
633638
checkoutPath,

0 commit comments

Comments
 (0)