Add catch-all error reporting for errors that slip through run

This commit is contained in:
Henry Mercer
2026-01-22 13:14:53 +00:00
parent 14bd76753f
commit 229e0cd749
17 changed files with 447 additions and 101 deletions

48
lib/analyze-action.js generated
View File

@@ -94410,6 +94410,27 @@ async function sendStatusReport(statusReport) {
);
}
}
async function sendUnexpectedErrorStatusReport(actionName, actionStartedAt, error3, logger) {
try {
const statusReport = await createStatusReportBase(
actionName,
"failure",
actionStartedAt,
void 0,
void 0,
logger,
void 0,
getErrorMessage(error3)
);
if (statusReport !== void 0) {
await sendStatusReport(statusReport);
}
} catch (e) {
logger.warning(
`Caught an exception while sending the error status report: ${e}.`
);
}
}
// src/upload-lib.ts
var fs15 = __toESM(require("fs"));
@@ -96241,12 +96262,12 @@ async function postProcessAndUploadSarif(logger, features, uploadKind, checkoutP
}
// src/analyze-action.ts
async function sendStatusReport2(startedAt, config, stats, error3, trapCacheUploadTime, dbCreationTimings, didUploadTrapCaches, trapCacheCleanup, dependencyCacheResults, databaseUploadResults, logger) {
async function sendStatusReport2(startedAt2, config, stats, error3, trapCacheUploadTime, dbCreationTimings, didUploadTrapCaches, trapCacheCleanup, dependencyCacheResults, databaseUploadResults, logger) {
const status = getActionsStatus(error3, stats?.analyze_failure_language);
const statusReportBase = await createStatusReportBase(
"finish" /* Analyze */,
status,
startedAt,
startedAt2,
config,
await checkDiskUsage(logger),
logger,
@@ -96332,8 +96353,7 @@ async function runAutobuildIfLegacyGoWorkflow(config, logger) {
);
await runAutobuild(config, "go" /* go */, logger);
}
async function run() {
const startedAt = /* @__PURE__ */ new Date();
async function run(startedAt2) {
let uploadResults = void 0;
let runStats = void 0;
let config = void 0;
@@ -96350,7 +96370,7 @@ async function run() {
const statusReportBase = await createStatusReportBase(
"finish" /* Analyze */,
"starting",
startedAt,
startedAt2,
config,
await checkDiskUsage(logger),
logger
@@ -96517,7 +96537,7 @@ async function run() {
core14.setFailed(error3.message);
}
await sendStatusReport2(
startedAt,
startedAt2,
config,
error3 instanceof CodeQLAnalysisError ? error3.queriesStatusReport : void 0,
error3 instanceof CodeQLAnalysisError ? error3.error : error3,
@@ -96533,7 +96553,7 @@ async function run() {
}
if (runStats !== void 0 && uploadResults?.["code-scanning" /* CodeScanning */] !== void 0) {
await sendStatusReport2(
startedAt,
startedAt2,
config,
{
...runStats,
@@ -96550,7 +96570,7 @@ async function run() {
);
} else if (runStats !== void 0) {
await sendStatusReport2(
startedAt,
startedAt2,
config,
{ ...runStats },
void 0,
@@ -96564,7 +96584,7 @@ async function run() {
);
} else {
await sendStatusReport2(
startedAt,
startedAt2,
config,
void 0,
void 0,
@@ -96578,12 +96598,20 @@ async function run() {
);
}
}
var runPromise = run();
var startedAt = /* @__PURE__ */ new Date();
var runPromise = run(startedAt);
async function runWrapper() {
const logger = getActionsLogger();
try {
await runPromise;
} catch (error3) {
core14.setFailed(`analyze action failed: ${getErrorMessage(error3)}`);
await sendUnexpectedErrorStatusReport(
"finish" /* Analyze */,
startedAt,
error3,
logger
);
}
await checkForTimeout();
}

View File

@@ -88882,6 +88882,27 @@ async function sendStatusReport(statusReport) {
);
}
}
async function sendUnexpectedErrorStatusReport(actionName, actionStartedAt, error3, logger) {
try {
const statusReport = await createStatusReportBase(
actionName,
"failure",
actionStartedAt,
void 0,
void 0,
logger,
void 0,
getErrorMessage(error3)
);
if (statusReport !== void 0) {
await sendStatusReport(statusReport);
}
} catch (e) {
logger.warning(
`Caught an exception while sending the error status report: ${e}.`
);
}
}
// src/autobuild-action.ts
async function sendCompletedStatusReport(config, logger, startedAt, allLanguages, failingLanguage, cause) {
@@ -88906,8 +88927,7 @@ async function sendCompletedStatusReport(config, logger, startedAt, allLanguages
await sendStatusReport(statusReport);
}
}
async function run() {
const startedAt = /* @__PURE__ */ new Date();
async function run(startedAt) {
const logger = getActionsLogger();
let config;
let currentLanguage;
@@ -88968,10 +88988,18 @@ async function run() {
await sendCompletedStatusReport(config, logger, startedAt, languages ?? []);
}
async function runWrapper() {
const startedAt = /* @__PURE__ */ new Date();
const logger = getActionsLogger();
try {
await run();
await run(startedAt);
} catch (error3) {
core13.setFailed(`autobuild action failed. ${getErrorMessage(error3)}`);
await sendUnexpectedErrorStatusReport(
"autobuild" /* Autobuild */,
startedAt,
error3,
logger
);
}
}
void runWrapper();

117
lib/init-action-post.js generated
View File

@@ -27121,7 +27121,7 @@ var require_light = __commonJS({
}
return this.Events.trigger("scheduled", { args: this.args, options: this.options });
}
async doExecute(chained, clearGlobalState, run2, free) {
async doExecute(chained, clearGlobalState, run3, free) {
var error3, eventInfo, passed;
if (this.retryCount === 0) {
this._assertStatus("RUNNING");
@@ -27141,10 +27141,10 @@ var require_light = __commonJS({
}
} catch (error1) {
error3 = error1;
return this._onFailure(error3, eventInfo, clearGlobalState, run2, free);
return this._onFailure(error3, eventInfo, clearGlobalState, run3, free);
}
}
doExpire(clearGlobalState, run2, free) {
doExpire(clearGlobalState, run3, free) {
var error3, eventInfo;
if (this._states.jobStatus(this.options.id === "RUNNING")) {
this._states.next(this.options.id);
@@ -27152,9 +27152,9 @@ var require_light = __commonJS({
this._assertStatus("EXECUTING");
eventInfo = { args: this.args, options: this.options, retryCount: this.retryCount };
error3 = new BottleneckError$1(`This job timed out after ${this.options.expiration} ms.`);
return this._onFailure(error3, eventInfo, clearGlobalState, run2, free);
return this._onFailure(error3, eventInfo, clearGlobalState, run3, free);
}
async _onFailure(error3, eventInfo, clearGlobalState, run2, free) {
async _onFailure(error3, eventInfo, clearGlobalState, run3, free) {
var retry3, retryAfter;
if (clearGlobalState()) {
retry3 = await this.Events.trigger("failed", error3, eventInfo);
@@ -27162,7 +27162,7 @@ var require_light = __commonJS({
retryAfter = ~~retry3;
this.Events.trigger("retry", `Retrying ${this.options.id} after ${retryAfter} ms`, eventInfo);
this.retryCount++;
return run2(retryAfter);
return run3(retryAfter);
} else {
this.doDone(eventInfo);
await free(this.options, eventInfo);
@@ -27800,17 +27800,17 @@ var require_light = __commonJS({
}
}
_run(index, job, wait) {
var clearGlobalState, free, run2;
var clearGlobalState, free, run3;
job.doRun();
clearGlobalState = this._clearGlobalState.bind(this, index);
run2 = this._run.bind(this, index, job);
run3 = this._run.bind(this, index, job);
free = this._free.bind(this, index, job);
return this._scheduled[index] = {
timeout: setTimeout(() => {
return job.doExecute(this._limiter, clearGlobalState, run2, free);
return job.doExecute(this._limiter, clearGlobalState, run3, free);
}, wait),
expiration: job.options.expiration != null ? setTimeout(function() {
return job.doExpire(clearGlobalState, run2, free);
return job.doExpire(clearGlobalState, run3, free);
}, wait + job.options.expiration) : void 0,
job
};
@@ -88091,8 +88091,8 @@ var require_async = __commonJS({
return callback(null, results);
}
while (readyTasks.length && runningTasks < concurrency) {
var run2 = readyTasks.shift();
run2();
var run3 = readyTasks.shift();
run3();
}
}
function addListener(taskName, fn) {
@@ -126644,8 +126644,8 @@ function getExtraOptionsEnvParam() {
}
function getToolNames(sarif) {
const toolNames = {};
for (const run2 of sarif.runs || []) {
const tool = run2.tool || {};
for (const run3 of sarif.runs || []) {
const tool = run3.tool || {};
const driver = tool.driver || {};
if (typeof driver.name === "string" && driver.name.length > 0) {
toolNames[driver.name] = true;
@@ -130773,6 +130773,27 @@ async function sendStatusReport(statusReport) {
);
}
}
async function sendUnexpectedErrorStatusReport(actionName, actionStartedAt, error3, logger) {
try {
const statusReport = await createStatusReportBase(
actionName,
"failure",
actionStartedAt,
void 0,
void 0,
logger,
void 0,
getErrorMessage(error3)
);
if (statusReport !== void 0) {
await sendStatusReport(statusReport);
}
} catch (e) {
logger.warning(
`Caught an exception while sending the error status report: ${e}.`
);
}
}
// src/upload-lib.ts
var fs15 = __toESM(require("fs"));
@@ -131861,9 +131882,9 @@ async function addFingerprints(sarif, sourceRoot, logger) {
`Adding fingerprints to SARIF file. See ${"https://docs.github.com/en/enterprise-cloud@latest/code-security/code-scanning/integrating-with-code-scanning/sarif-support-for-code-scanning#providing-data-to-track-code-scanning-alerts-across-runs" /* TRACK_CODE_SCANNING_ALERTS_ACROSS_RUNS */} for more information.`
);
const callbacksByFile = {};
for (const run2 of sarif.runs || []) {
const artifacts = run2.artifacts || [];
for (const result of run2.results || []) {
for (const run3 of sarif.runs || []) {
const artifacts = run3.artifacts || [];
for (const result of run3.results || []) {
const primaryLocation = (result.locations || [])[0];
if (!primaryLocation?.physicalLocation?.artifactLocation) {
logger.debug(
@@ -131964,25 +131985,25 @@ function combineSarifFiles(sarifFiles, logger) {
function areAllRunsProducedByCodeQL(sarifObjects) {
return sarifObjects.every((sarifObject) => {
return sarifObject.runs?.every(
(run2) => run2.tool?.driver?.name === "CodeQL"
(run3) => run3.tool?.driver?.name === "CodeQL"
);
});
}
function createRunKey(run2) {
function createRunKey(run3) {
return {
name: run2.tool?.driver?.name,
fullName: run2.tool?.driver?.fullName,
version: run2.tool?.driver?.version,
semanticVersion: run2.tool?.driver?.semanticVersion,
guid: run2.tool?.driver?.guid,
automationId: run2.automationDetails?.id
name: run3.tool?.driver?.name,
fullName: run3.tool?.driver?.fullName,
version: run3.tool?.driver?.version,
semanticVersion: run3.tool?.driver?.semanticVersion,
guid: run3.tool?.driver?.guid,
automationId: run3.automationDetails?.id
};
}
function areAllRunsUnique(sarifObjects) {
const keys = /* @__PURE__ */ new Set();
for (const sarifObject of sarifObjects) {
for (const run2 of sarifObject.runs) {
const key = JSON.stringify(createRunKey(run2));
for (const run3 of sarifObject.runs) {
const key = JSON.stringify(createRunKey(run3));
if (keys.has(key)) {
return false;
}
@@ -132085,9 +132106,9 @@ async function combineSarifFilesUsingCLI(sarifFiles, gitHubVersion, features, lo
function populateRunAutomationDetails(sarif, category, analysis_key, environment) {
const automationID = getAutomationID2(category, analysis_key, environment);
if (automationID !== void 0) {
for (const run2 of sarif.runs || []) {
if (run2.automationDetails === void 0) {
run2.automationDetails = {
for (const run3 of sarif.runs || []) {
if (run3.automationDetails === void 0) {
run3.automationDetails = {
id: automationID
};
}
@@ -132186,13 +132207,13 @@ function countResultsInSarif(sarif) {
if (!Array.isArray(parsedSarif.runs)) {
throw new InvalidSarifUploadError("Invalid SARIF. Missing 'runs' array.");
}
for (const run2 of parsedSarif.runs) {
if (!Array.isArray(run2.results)) {
for (const run3 of parsedSarif.runs) {
if (!Array.isArray(run3.results)) {
throw new InvalidSarifUploadError(
"Invalid SARIF. Missing 'results' array in run."
);
}
numResults += run2.results.length;
numResults += run3.results.length;
}
return numResults;
}
@@ -132483,9 +132504,9 @@ function handleProcessingResultForUnsuccessfulExecution(response, status, logger
}
function validateUniqueCategory(sarif, sentinelPrefix) {
const categories = {};
for (const run2 of sarif.runs) {
const id = run2?.automationDetails?.id;
const tool = run2.tool?.driver?.name;
for (const run3 of sarif.runs) {
const id = run3?.automationDetails?.id;
const tool = run3.tool?.driver?.name;
const category = `${sanitize(id)}_${sanitize(tool)}`;
categories[category] = { id, tool };
}
@@ -132513,9 +132534,9 @@ function filterAlertsByDiffRange(logger, sarif) {
return sarif;
}
const checkoutPath = getRequiredInput("checkout_path");
for (const run2 of sarif.runs) {
if (run2.results) {
run2.results = run2.results.filter((result) => {
for (const run3 of sarif.runs) {
if (run3.results) {
run3.results = run3.results.filter((result) => {
const locations = [
...(result.locations || []).map((loc) => loc.physicalLocation),
...(result.relatedLocations || []).map((loc) => loc.physicalLocation)
@@ -132881,9 +132902,8 @@ function getFinalJobStatus() {
}
// src/init-action-post.ts
async function runWrapper() {
async function run2(startedAt) {
const logger = getActionsLogger();
const startedAt = /* @__PURE__ */ new Date();
let config;
let uploadFailedSarifResult;
let dependencyCachingUsage;
@@ -132958,6 +132978,21 @@ async function runWrapper() {
logger.info("Status report sent for init-post step.");
}
}
async function runWrapper() {
const startedAt = /* @__PURE__ */ new Date();
const logger = getActionsLogger();
try {
await run2(startedAt);
} catch (error3) {
core17.setFailed(`init post action failed: ${wrapError(error3).message}`);
await sendUnexpectedErrorStatusReport(
"init-post" /* InitPost */,
startedAt,
error3,
logger
);
}
}
void runWrapper();
/*! Bundled license information:

34
lib/init-action.js generated
View File

@@ -92247,6 +92247,27 @@ async function createInitWithConfigStatusReport(config, initStatusReport, config
)
};
}
async function sendUnexpectedErrorStatusReport(actionName, actionStartedAt, error3, logger) {
try {
const statusReport = await createStatusReportBase(
actionName,
"failure",
actionStartedAt,
void 0,
void 0,
logger,
void 0,
getErrorMessage(error3)
);
if (statusReport !== void 0) {
await sendStatusReport(statusReport);
}
} catch (e) {
logger.warning(
`Caught an exception while sending the error status report: ${e}.`
);
}
}
// src/workflow.ts
var fs13 = __toESM(require("fs"));
@@ -92503,8 +92524,7 @@ async function sendCompletedStatusReport(startedAt, config, configFile, toolsDow
await sendStatusReport({ ...initStatusReport, ...initToolsDownloadFields });
}
}
async function run() {
const startedAt = /* @__PURE__ */ new Date();
async function run(startedAt) {
const logger = getActionsLogger();
let apiDetails;
let config;
@@ -92935,10 +92955,18 @@ async function recordZstdAvailability(config, zstdAvailability) {
);
}
async function runWrapper() {
const startedAt = /* @__PURE__ */ new Date();
const logger = getActionsLogger();
try {
await run();
await run(startedAt);
} catch (error3) {
core13.setFailed(`init action failed: ${getErrorMessage(error3)}`);
await sendUnexpectedErrorStatusReport(
"init" /* Init */,
startedAt,
error3,
logger
);
}
await checkForTimeout();
}

View File

@@ -88502,11 +88502,31 @@ async function sendStatusReport(statusReport) {
);
}
}
async function sendUnexpectedErrorStatusReport(actionName, actionStartedAt, error3, logger) {
try {
const statusReport = await createStatusReportBase(
actionName,
"failure",
actionStartedAt,
void 0,
void 0,
logger,
void 0,
getErrorMessage(error3)
);
if (statusReport !== void 0) {
await sendStatusReport(statusReport);
}
} catch (e) {
logger.warning(
`Caught an exception while sending the error status report: ${e}.`
);
}
}
// src/resolve-environment-action.ts
var ENVIRONMENT_OUTPUT_NAME = "environment";
async function run() {
const startedAt = /* @__PURE__ */ new Date();
async function run(startedAt) {
const logger = getActionsLogger();
let config;
try {
@@ -88578,14 +88598,22 @@ async function run() {
}
}
async function runWrapper() {
const startedAt = /* @__PURE__ */ new Date();
const logger = getActionsLogger();
try {
await run();
await run(startedAt);
} catch (error3) {
core12.setFailed(
`${"resolve-environment" /* ResolveEnvironment */} action failed: ${getErrorMessage(
error3
)}`
);
await sendUnexpectedErrorStatusReport(
"resolve-environment" /* ResolveEnvironment */,
startedAt,
error3,
logger
);
}
await checkForTimeout();
}

View File

@@ -89829,6 +89829,27 @@ async function sendStatusReport(statusReport) {
);
}
}
async function sendUnexpectedErrorStatusReport(actionName, actionStartedAt, error3, logger) {
try {
const statusReport = await createStatusReportBase(
actionName,
"failure",
actionStartedAt,
void 0,
void 0,
logger,
void 0,
getErrorMessage(error3)
);
if (statusReport !== void 0) {
await sendStatusReport(statusReport);
}
} catch (e) {
logger.warning(
`Caught an exception while sending the error status report: ${e}.`
);
}
}
// src/setup-codeql-action.ts
async function sendCompletedStatusReport(startedAt, toolsDownloadStatusReport, toolsFeatureFlagsValid, toolsSource, toolsVersion, logger, error3) {
@@ -89861,8 +89882,7 @@ async function sendCompletedStatusReport(startedAt, toolsDownloadStatusReport, t
}
await sendStatusReport({ ...initStatusReport, ...initToolsDownloadFields });
}
async function run() {
const startedAt = /* @__PURE__ */ new Date();
async function run(startedAt) {
const logger = getActionsLogger();
let codeql;
let toolsDownloadStatusReport;
@@ -89949,10 +89969,18 @@ async function run() {
);
}
async function runWrapper() {
const startedAt = /* @__PURE__ */ new Date();
const logger = getActionsLogger();
try {
await run();
await run(startedAt);
} catch (error3) {
core12.setFailed(`setup-codeql action failed: ${getErrorMessage(error3)}`);
await sendUnexpectedErrorStatusReport(
"setup-codeql" /* SetupCodeQL */,
startedAt,
error3,
logger
);
}
await checkForTimeout();
}

View File

@@ -45727,7 +45727,7 @@ var require_light = __commonJS({
}
return this.Events.trigger("scheduled", { args: this.args, options: this.options });
}
async doExecute(chained, clearGlobalState, run, free) {
async doExecute(chained, clearGlobalState, run2, free) {
var error3, eventInfo, passed;
if (this.retryCount === 0) {
this._assertStatus("RUNNING");
@@ -45747,10 +45747,10 @@ var require_light = __commonJS({
}
} catch (error1) {
error3 = error1;
return this._onFailure(error3, eventInfo, clearGlobalState, run, free);
return this._onFailure(error3, eventInfo, clearGlobalState, run2, free);
}
}
doExpire(clearGlobalState, run, free) {
doExpire(clearGlobalState, run2, free) {
var error3, eventInfo;
if (this._states.jobStatus(this.options.id === "RUNNING")) {
this._states.next(this.options.id);
@@ -45758,9 +45758,9 @@ var require_light = __commonJS({
this._assertStatus("EXECUTING");
eventInfo = { args: this.args, options: this.options, retryCount: this.retryCount };
error3 = new BottleneckError$1(`This job timed out after ${this.options.expiration} ms.`);
return this._onFailure(error3, eventInfo, clearGlobalState, run, free);
return this._onFailure(error3, eventInfo, clearGlobalState, run2, free);
}
async _onFailure(error3, eventInfo, clearGlobalState, run, free) {
async _onFailure(error3, eventInfo, clearGlobalState, run2, free) {
var retry3, retryAfter;
if (clearGlobalState()) {
retry3 = await this.Events.trigger("failed", error3, eventInfo);
@@ -45768,7 +45768,7 @@ var require_light = __commonJS({
retryAfter = ~~retry3;
this.Events.trigger("retry", `Retrying ${this.options.id} after ${retryAfter} ms`, eventInfo);
this.retryCount++;
return run(retryAfter);
return run2(retryAfter);
} else {
this.doDone(eventInfo);
await free(this.options, eventInfo);
@@ -46406,17 +46406,17 @@ var require_light = __commonJS({
}
}
_run(index, job, wait) {
var clearGlobalState, free, run;
var clearGlobalState, free, run2;
job.doRun();
clearGlobalState = this._clearGlobalState.bind(this, index);
run = this._run.bind(this, index, job);
run2 = this._run.bind(this, index, job);
free = this._free.bind(this, index, job);
return this._scheduled[index] = {
timeout: setTimeout(() => {
return job.doExecute(this._limiter, clearGlobalState, run, free);
return job.doExecute(this._limiter, clearGlobalState, run2, free);
}, wait),
expiration: job.options.expiration != null ? setTimeout(function() {
return job.doExpire(clearGlobalState, run, free);
return job.doExpire(clearGlobalState, run2, free);
}, wait + job.options.expiration) : void 0,
job
};
@@ -104666,6 +104666,27 @@ async function sendStatusReport(statusReport) {
);
}
}
async function sendUnexpectedErrorStatusReport(actionName, actionStartedAt, error3, logger) {
try {
const statusReport = await createStatusReportBase(
actionName,
"failure",
actionStartedAt,
void 0,
void 0,
logger,
void 0,
getErrorMessage(error3)
);
if (statusReport !== void 0) {
await sendStatusReport(statusReport);
}
} catch (e) {
logger.warning(
`Caught an exception while sending the error status report: ${e}.`
);
}
}
// src/start-proxy-action.ts
var KEY_SIZE = 2048;
@@ -104731,8 +104752,7 @@ async function sendSuccessStatusReport(startedAt, config, registry_types, logger
await sendStatusReport(statusReport);
}
}
async function runWrapper() {
const startedAt = /* @__PURE__ */ new Date();
async function run(startedAt) {
const logger = getActionsLogger();
let language;
try {
@@ -104789,6 +104809,21 @@ async function runWrapper() {
}
}
}
async function runWrapper() {
const startedAt = /* @__PURE__ */ new Date();
const logger = getActionsLogger();
try {
await run(startedAt);
} catch (error3) {
core11.setFailed(`start-proxy action failed: ${getErrorMessage(error3)}`);
await sendUnexpectedErrorStatusReport(
"start-proxy" /* StartProxy */,
startedAt,
error3,
logger
);
}
}
async function startProxy(binPath, config, logFilePath, logger) {
const host = "127.0.0.1";
let port = 49152;

View File

@@ -91059,6 +91059,27 @@ async function sendStatusReport(statusReport) {
);
}
}
async function sendUnexpectedErrorStatusReport(actionName, actionStartedAt, error3, logger) {
try {
const statusReport = await createStatusReportBase(
actionName,
"failure",
actionStartedAt,
void 0,
void 0,
logger,
void 0,
getErrorMessage(error3)
);
if (statusReport !== void 0) {
await sendStatusReport(statusReport);
}
} catch (e) {
logger.warning(
`Caught an exception while sending the error status report: ${e}.`
);
}
}
// src/upload-lib.ts
var fs12 = __toESM(require("fs"));
@@ -94702,8 +94723,7 @@ async function sendSuccessStatusReport(startedAt, uploadStats, logger) {
await sendStatusReport(statusReport);
}
}
async function run() {
const startedAt = /* @__PURE__ */ new Date();
async function run(startedAt) {
const logger = getActionsLogger();
try {
initializeEnvironment(getActionVersion());
@@ -94788,12 +94808,20 @@ async function run() {
}
}
async function runWrapper() {
const startedAt = /* @__PURE__ */ new Date();
const logger = getActionsLogger();
try {
await run();
await run(startedAt);
} catch (error3) {
core13.setFailed(
`codeql/upload-sarif action failed: ${getErrorMessage(error3)}`
);
await sendUnexpectedErrorStatusReport(
"upload-sarif" /* UploadSarif */,
startedAt,
error3,
logger
);
}
}
void runWrapper();

View File

@@ -41,6 +41,7 @@ import {
createStatusReportBase,
DatabaseCreationTimings,
getActionsStatus,
sendUnexpectedErrorStatusReport,
StatusReportBase,
} from "./status-report";
import {
@@ -208,11 +209,10 @@ async function runAutobuildIfLegacyGoWorkflow(config: Config, logger: Logger) {
await runAutobuild(config, KnownLanguage.go, logger);
}
async function run() {
async function run(startedAt: Date) {
// To capture errors appropriately, keep as much code within the try-catch as
// possible, and only use safe functions outside.
const startedAt = new Date();
let uploadResults:
| Partial<Record<analyses.AnalysisKind, UploadResult>>
| undefined = undefined;
@@ -526,13 +526,22 @@ async function run() {
}
}
export const runPromise = run();
// Module-level startedAt so it can be accessed by runWrapper for error reporting
const startedAt = new Date();
export const runPromise = run(startedAt);
async function runWrapper() {
const logger = getActionsLogger();
try {
await runPromise;
} catch (error) {
core.setFailed(`analyze action failed: ${util.getErrorMessage(error)}`);
await sendUnexpectedErrorStatusReport(
ActionName.Analyze,
startedAt,
error,
logger,
);
}
await util.checkForTimeout();
}

View File

@@ -17,6 +17,7 @@ import {
getActionsStatus,
createStatusReportBase,
sendStatusReport,
sendUnexpectedErrorStatusReport,
ActionName,
} from "./status-report";
import { endTracingForCluster } from "./tracer-config";
@@ -68,11 +69,10 @@ async function sendCompletedStatusReport(
}
}
async function run() {
async function run(startedAt: Date) {
// To capture errors appropriately, keep as much code within the try-catch as
// possible, and only use safe functions outside.
const startedAt = new Date();
const logger = getActionsLogger();
let config: Config | undefined;
let currentLanguage: Language | undefined;
@@ -143,10 +143,18 @@ async function run() {
}
async function runWrapper() {
const startedAt = new Date();
const logger = getActionsLogger();
try {
await run();
await run(startedAt);
} catch (error) {
core.setFailed(`autobuild action failed. ${getErrorMessage(error)}`);
await sendUnexpectedErrorStatusReport(
ActionName.Autobuild,
startedAt,
error,
logger,
);
}
}

View File

@@ -28,6 +28,7 @@ import { getRepositoryNwo } from "./repository";
import {
StatusReportBase,
sendStatusReport,
sendUnexpectedErrorStatusReport,
createStatusReportBase,
getActionsStatus,
ActionName,
@@ -41,12 +42,11 @@ interface InitPostStatusReport
initActionPostHelper.JobStatusReport,
initActionPostHelper.DependencyCachingUsageReport {}
async function runWrapper() {
async function run(startedAt: Date) {
// To capture errors appropriately, keep as much code within the try-catch as
// possible, and only use safe functions outside.
const logger = getActionsLogger();
const startedAt = new Date();
let config: Config | undefined;
let uploadFailedSarifResult:
| initActionPostHelper.UploadFailedSarifResult
@@ -139,4 +139,20 @@ async function runWrapper() {
}
}
async function runWrapper() {
const startedAt = new Date();
const logger = getActionsLogger();
try {
await run(startedAt);
} catch (error) {
core.setFailed(`init post action failed: ${wrapError(error).message}`);
await sendUnexpectedErrorStatusReport(
ActionName.InitPost,
startedAt,
error,
logger,
);
}
}
void runWrapper();

View File

@@ -64,6 +64,7 @@ import {
createStatusReportBase,
getActionsStatus,
sendStatusReport,
sendUnexpectedErrorStatusReport,
} from "./status-report";
import { ZstdAvailability } from "./tar";
import { ToolsDownloadStatusReport } from "./tools-download";
@@ -191,11 +192,10 @@ async function sendCompletedStatusReport(
}
}
async function run() {
async function run(startedAt: Date) {
// To capture errors appropriately, keep as much code within the try-catch as
// possible, and only use safe functions outside.
const startedAt = new Date();
const logger = getActionsLogger();
let apiDetails: GitHubApiCombinedDetails;
@@ -805,10 +805,18 @@ async function recordZstdAvailability(
}
async function runWrapper() {
const startedAt = new Date();
const logger = getActionsLogger();
try {
await run();
await run(startedAt);
} catch (error) {
core.setFailed(`init action failed: ${getErrorMessage(error)}`);
await sendUnexpectedErrorStatusReport(
ActionName.Init,
startedAt,
error,
logger,
);
}
await checkForTimeout();
}

View File

@@ -13,6 +13,7 @@ import { getActionsLogger } from "./logging";
import { runResolveBuildEnvironment } from "./resolve-environment";
import {
sendStatusReport,
sendUnexpectedErrorStatusReport,
createStatusReportBase,
getActionsStatus,
ActionName,
@@ -29,11 +30,10 @@ import {
const ENVIRONMENT_OUTPUT_NAME = "environment";
async function run() {
async function run(startedAt: Date) {
// To capture errors appropriately, keep as much code within the try-catch as
// possible, and only use safe functions outside.
const startedAt = new Date();
const logger = getActionsLogger();
let config: Config | undefined;
@@ -118,14 +118,22 @@ async function run() {
}
async function runWrapper() {
const startedAt = new Date();
const logger = getActionsLogger();
try {
await run();
await run(startedAt);
} catch (error) {
core.setFailed(
`${ActionName.ResolveEnvironment} action failed: ${getErrorMessage(
error,
)}`,
);
await sendUnexpectedErrorStatusReport(
ActionName.ResolveEnvironment,
startedAt,
error,
logger,
);
}
await checkForTimeout();
}

View File

@@ -22,6 +22,7 @@ import {
createStatusReportBase,
getActionsStatus,
sendStatusReport,
sendUnexpectedErrorStatusReport,
} from "./status-report";
import { ToolsDownloadStatusReport } from "./tools-download";
import {
@@ -85,11 +86,10 @@ async function sendCompletedStatusReport(
}
/** The main behaviour of this action. */
async function run(): Promise<void> {
async function run(startedAt: Date): Promise<void> {
// To capture errors appropriately, keep as much code within the try-catch as
// possible, and only use safe functions outside.
const startedAt = new Date();
const logger = getActionsLogger();
let codeql: CodeQL;
@@ -189,10 +189,18 @@ async function run(): Promise<void> {
/** Run the action and catch any unhandled errors. */
async function runWrapper(): Promise<void> {
const startedAt = new Date();
const logger = getActionsLogger();
try {
await run();
await run(startedAt);
} catch (error) {
core.setFailed(`setup-codeql action failed: ${getErrorMessage(error)}`);
await sendUnexpectedErrorStatusReport(
ActionName.SetupCodeQL,
startedAt,
error,
logger,
);
}
await checkForTimeout();
}

View File

@@ -22,6 +22,7 @@ import {
createStatusReportBase,
getActionsStatus,
sendStatusReport,
sendUnexpectedErrorStatusReport,
StatusReportBase,
} from "./status-report";
import * as util from "./util";
@@ -122,12 +123,10 @@ async function sendSuccessStatusReport(
}
}
async function runWrapper() {
async function run(startedAt: Date) {
// To capture errors appropriately, keep as much code within the try-catch as
// possible, and only use safe functions outside.
const startedAt = new Date();
const logger = getActionsLogger();
let language: KnownLanguage | undefined;
@@ -203,6 +202,23 @@ async function runWrapper() {
}
}
async function runWrapper() {
const startedAt = new Date();
const logger = getActionsLogger();
try {
await run(startedAt);
} catch (error) {
core.setFailed(`start-proxy action failed: ${util.getErrorMessage(error)}`);
await sendUnexpectedErrorStatusReport(
ActionName.StartProxy,
startedAt,
error,
logger,
);
}
}
async function startProxy(
binPath: string,
config: ProxyConfig,

View File

@@ -606,3 +606,30 @@ export async function createInitWithConfigStatusReport(
),
};
}
export async function sendUnexpectedErrorStatusReport(
actionName: ActionName,
actionStartedAt: Date,
error: unknown,
logger: Logger,
): Promise<void> {
try {
const statusReport = await createStatusReportBase(
actionName,
"failure",
actionStartedAt,
undefined,
undefined,
logger,
undefined,
getErrorMessage(error),
);
if (statusReport !== undefined) {
await sendStatusReport(statusReport);
}
} catch (e) {
logger.warning(
`Caught an exception while sending the error status report: ${e}.`,
);
}
}

View File

@@ -10,6 +10,7 @@ import { getRepositoryNwo } from "./repository";
import {
createStatusReportBase,
sendStatusReport,
sendUnexpectedErrorStatusReport,
StatusReportBase,
getActionsStatus,
ActionName,
@@ -53,11 +54,10 @@ async function sendSuccessStatusReport(
}
}
async function run() {
async function run(startedAt: Date) {
// To capture errors appropriately, keep as much code within the try-catch as
// possible, and only use safe functions outside.
const startedAt = new Date();
const logger = getActionsLogger();
try {
@@ -165,12 +165,20 @@ async function run() {
}
async function runWrapper() {
const startedAt = new Date();
const logger = getActionsLogger();
try {
await run();
await run(startedAt);
} catch (error) {
core.setFailed(
`codeql/upload-sarif action failed: ${getErrorMessage(error)}`,
);
await sendUnexpectedErrorStatusReport(
ActionName.UploadSarif,
startedAt,
error,
logger,
);
}
}