Add transformTelemetryError option to Action

This commit is contained in:
Michael B. Gale
2026-07-29 14:39:30 +01:00
parent b411bbcd4a
commit ba46ff760e
2 changed files with 25 additions and 3 deletions

8
lib/entry-points.js generated
View File

@@ -146713,7 +146713,13 @@ async function runInActions(action) {
core8.setFailed( core8.setFailed(
`${getDisplayActionName(action.name)} action failed: ${getErrorMessage(error3)}` `${getDisplayActionName(action.name)} action failed: ${getErrorMessage(error3)}`
); );
await sendUnhandledErrorStatusReport(action.name, startedAt, error3, logger); const statusReportError = action.transformTelemetryError !== void 0 ? action.transformTelemetryError(wrapError(error3)) : error3;
await sendUnhandledErrorStatusReport(
action.name,
startedAt,
statusReportError,
logger
);
} }
} }

View File

@@ -11,7 +11,7 @@ import {
getJobUUID, getJobUUID,
sendUnhandledErrorStatusReport, sendUnhandledErrorStatusReport,
} from "./status-report"; } from "./status-report";
import { getEnv, getErrorMessage } from "./util"; import { getEnv, getErrorMessage, wrapError } from "./util";
/** Base state that is available to an Action on startup. */ /** Base state that is available to an Action on startup. */
export interface BaseState { export interface BaseState {
@@ -79,6 +79,12 @@ export interface Action {
name: ActionName; name: ActionName;
/** The entry point for the Action. */ /** The entry point for the Action. */
run: ActionMain; run: ActionMain;
/**
* An optional function that transforms a caught error into a message suitable for
* inclusion in a status report. This is primarily intended for the `start-proxy`
* action to replace the thrown `Error`'s message with a safe one.
*/
transformTelemetryError?: (error: Error) => string;
} }
/** A generic entry point that sets up the basic environment for the `action` and runs it. */ /** A generic entry point that sets up the basic environment for the `action` and runs it. */
@@ -105,6 +111,16 @@ export async function runInActions(action: Action) {
core.setFailed( core.setFailed(
`${getDisplayActionName(action.name)} action failed: ${getErrorMessage(error)}`, `${getDisplayActionName(action.name)} action failed: ${getErrorMessage(error)}`,
); );
await sendUnhandledErrorStatusReport(action.name, startedAt, error, logger);
const statusReportError =
action.transformTelemetryError !== undefined
? action.transformTelemetryError(wrapError(error))
: error;
await sendUnhandledErrorStatusReport(
action.name,
startedAt,
statusReportError,
logger,
);
} }
} }