diff --git a/packages/core/__tests__/core.test.ts b/packages/core/__tests__/core.test.ts index a5048e176b..d10e0590d8 100644 --- a/packages/core/__tests__/core.test.ts +++ b/packages/core/__tests__/core.test.ts @@ -169,6 +169,12 @@ describe('@actions/core', () => { assertWriteCalls([`::warning::%0D%0Awarning%0A${os.EOL}`]) }) + it('warning handles an error object', () => { + const message = 'this is my error message' + core.warning(new Error(message)) + assertWriteCalls([`::warning::Error: ${message}${os.EOL}`]) + }) + it('startGroup starts a new group', () => { core.startGroup('my-group') assertWriteCalls([`::group::my-group${os.EOL}`]) diff --git a/packages/core/src/core.ts b/packages/core/src/core.ts index 5aa0e3cfb9..2e2dba4ef6 100644 --- a/packages/core/src/core.ts +++ b/packages/core/src/core.ts @@ -33,7 +33,7 @@ export enum ExitCode { /** * Sets env variable for this action and future actions in the job * @param name the name of the variable to set - * @param val the value of the variable. Will be converted to a string via JSON.stringify + * @param val the value of the variable. Non-string values will be converted to a string via JSON.stringify */ // eslint-disable-next-line @typescript-eslint/no-explicit-any export function exportVariable(name: string, val: any): void { @@ -80,7 +80,7 @@ export function getInput(name: string, options?: InputOptions): string { * Sets the value of an output. * * @param name name of the output to set - * @param value value to store. Will be converted to a string via JSON.stringify + * @param value value to store. Non-string values will be converted to a string via JSON.stringify */ // eslint-disable-next-line @typescript-eslint/no-explicit-any export function setOutput(name: string, value: any): void { @@ -123,7 +123,7 @@ export function debug(message: string): void { /** * Adds an error issue - * @param message error issue message + * @param message error issue message. Errors will be converted to string via toString() */ export function error(message: string | Error): void { issue('error', message instanceof Error ? message.toString() : message) @@ -131,10 +131,10 @@ export function error(message: string | Error): void { /** * Adds an warning issue - * @param message warning issue message + * @param message warning issue message. Errors will be converted to string via toString() */ -export function warning(message: string): void { - issue('warning', message) +export function warning(message: string | Error): void { + issue('warning', message instanceof Error ? message.toString() : message) } /** @@ -193,11 +193,11 @@ export async function group(name: string, fn: () => Promise): Promise { * Saves state for current action, the state can only be retrieved by this action's post job execution. * * @param name name of the state to store - * @param value value to store + * @param value value to store. Non-string values will be converted to a string via JSON.stringify */ export function saveState( name: string, - value: string | number | boolean + value: any ): void { issueCommand('save-state', {name}, value) }