diff --git a/src/analyze-action-post.ts b/src/analyze-action-post.ts index ce8ddd31b..c83c10282 100644 --- a/src/analyze-action-post.ts +++ b/src/analyze-action-post.ts @@ -21,6 +21,9 @@ import { getActionsLogger } from "./logging"; import { checkGitHubVersionInRange, getErrorMessage } from "./util"; async function runWrapper() { + // To capture errors appropriately, keep as much code within the try-catch as + // possible, and only use safe functions outside. + try { actionsUtil.restoreInputs(); const logger = getActionsLogger(); diff --git a/src/analyze-action.ts b/src/analyze-action.ts index f39fc3608..460e6d55a 100644 --- a/src/analyze-action.ts +++ b/src/analyze-action.ts @@ -209,6 +209,9 @@ async function runAutobuildIfLegacyGoWorkflow(config: Config, logger: Logger) { } async function run() { + // 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> diff --git a/src/autobuild-action.ts b/src/autobuild-action.ts index 0cdf198a4..b09bff69b 100644 --- a/src/autobuild-action.ts +++ b/src/autobuild-action.ts @@ -69,6 +69,9 @@ async function sendCompletedStatusReport( } async function run() { + // 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; diff --git a/src/init-action-post.ts b/src/init-action-post.ts index 9a93f38bc..59979dca8 100644 --- a/src/init-action-post.ts +++ b/src/init-action-post.ts @@ -42,6 +42,9 @@ interface InitPostStatusReport initActionPostHelper.DependencyCachingUsageReport {} async function runWrapper() { + // 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; diff --git a/src/init-action.ts b/src/init-action.ts index 19eecbde1..55ea187a3 100644 --- a/src/init-action.ts +++ b/src/init-action.ts @@ -192,6 +192,9 @@ async function sendCompletedStatusReport( } async function run() { + // 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(); diff --git a/src/resolve-environment-action.ts b/src/resolve-environment-action.ts index 459f471ae..4f68fb8ac 100644 --- a/src/resolve-environment-action.ts +++ b/src/resolve-environment-action.ts @@ -30,6 +30,9 @@ import { const ENVIRONMENT_OUTPUT_NAME = "environment"; async function run() { + // 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(); diff --git a/src/setup-codeql-action.ts b/src/setup-codeql-action.ts index 664bf69e8..166e3c2de 100644 --- a/src/setup-codeql-action.ts +++ b/src/setup-codeql-action.ts @@ -86,6 +86,9 @@ async function sendCompletedStatusReport( /** The main behaviour of this action. */ async function run(): Promise { + // 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(); diff --git a/src/start-proxy-action-post.ts b/src/start-proxy-action-post.ts index c1e3209d1..5a1d8d6fc 100644 --- a/src/start-proxy-action-post.ts +++ b/src/start-proxy-action-post.ts @@ -13,6 +13,9 @@ import { getActionsLogger } from "./logging"; import { checkGitHubVersionInRange, getErrorMessage } from "./util"; async function runWrapper() { + // To capture errors appropriately, keep as much code within the try-catch as + // possible, and only use safe functions outside. + const logger = getActionsLogger(); try { diff --git a/src/start-proxy-action.ts b/src/start-proxy-action.ts index 094ecc352..98b765291 100644 --- a/src/start-proxy-action.ts +++ b/src/start-proxy-action.ts @@ -123,6 +123,9 @@ async function sendSuccessStatusReport( } async function runWrapper() { + // 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(); diff --git a/src/upload-sarif-action-post.ts b/src/upload-sarif-action-post.ts index 9852b882b..a184916de 100644 --- a/src/upload-sarif-action-post.ts +++ b/src/upload-sarif-action-post.ts @@ -13,6 +13,9 @@ import { getActionsLogger, withGroup } from "./logging"; import { checkGitHubVersionInRange, getErrorMessage } from "./util"; async function runWrapper() { + // To capture errors appropriately, keep as much code within the try-catch as + // possible, and only use safe functions outside. + try { // Restore inputs from `upload-sarif` Action. actionsUtil.restoreInputs(); diff --git a/src/upload-sarif-action.ts b/src/upload-sarif-action.ts index c676d43da..e37a7c524 100644 --- a/src/upload-sarif-action.ts +++ b/src/upload-sarif-action.ts @@ -54,6 +54,9 @@ async function sendSuccessStatusReport( } async function run() { + // 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();