Skip to content

Commit

Permalink
Add Errors to warnings as well
Browse files Browse the repository at this point in the history
  • Loading branch information
thboop committed Apr 9, 2020
1 parent 0c74104 commit 3ab3ad1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
6 changes: 6 additions & 0 deletions packages/core/__tests__/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`])
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -123,18 +123,18 @@ 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)
}

/**
* 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)
}

/**
Expand Down Expand Up @@ -193,11 +193,11 @@ export async function group<T>(name: string, fn: () => Promise<T>): Promise<T> {
* 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)
}
Expand Down

0 comments on commit 3ab3ad1

Please sign in to comment.