Skip to content

Commit

Permalink
Push unsuccessful execution API error detection into upload library
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Mercer committed Nov 29, 2022
1 parent 7fc3c60 commit e628ee0
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 32 deletions.
14 changes: 2 additions & 12 deletions lib/init-action-post-helper.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/init-action-post-helper.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion lib/upload-lib.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/upload-lib.js.map

Large diffs are not rendered by default.

23 changes: 7 additions & 16 deletions src/init-action-post-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,13 @@ async function uploadFailedSarif(
category,
logger
);
if (uploadResult !== undefined && waitForProcessing) {
try {
await uploadLib.waitForProcessing(
repositoryNwo,
uploadResult.sarifID,
logger
);
} catch (e) {
if (e instanceof Error && e.message.includes("unsuccessful execution")) {
logger.info(
"Submitting a SARIF file for the failed run isn't yet supported, continuing."
);
} else {
throw e;
}
}
if (waitForProcessing) {
await uploadLib.waitForProcessing(
repositoryNwo,
uploadResult.sarifID,
logger,
{ isUnsuccessfulExecution: true }
);
}
}

Expand Down
27 changes: 26 additions & 1 deletion src/upload-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,10 @@ const STATUS_CHECK_TIMEOUT_MILLISECONDS = 2 * 60 * 1000;
export async function waitForProcessing(
repositoryNwo: RepositoryNwo,
sarifID: string,
logger: Logger
logger: Logger,
options: { isUnsuccessfulExecution: boolean } = {
isUnsuccessfulExecution: false,
}
): Promise<void> {
logger.startGroup("Waiting for processing to finish");
try {
Expand Down Expand Up @@ -427,6 +430,28 @@ export async function waitForProcessing(
}
const status = response.data.processing_status;
logger.info(`Analysis upload status is ${status}.`);

if (
options.isUnsuccessfulExecution &&
status === "failed" &&
Array.isArray(response.data.errors) &&
response.data.errors.length === 1 &&
response.data.errors[0].toString().startsWith("unsuccessful execution")
) {
logger.debug(
"Successfully uploaded a SARIF file for the unsuccessful execution. Received expected " +
'"unsuccessful execution" error, and no other errors.'
);
break;
} else if (options.isUnsuccessfulExecution && status !== "pending") {
throw new Error(
`${
"Did not receive expected 'unsuccessful execution' error from the API. " +
"Code scanning status information may be out of date."
}${status === "failed" ? `\n${response.data.errors}` : ""}`
);
}

if (status === "complete") {
break;
} else if (status === "pending") {
Expand Down

0 comments on commit e628ee0

Please sign in to comment.