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 508796f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions packages/core/__tests__/core.test.ts
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
12 changes: 6 additions & 6 deletions packages/core/src/core.ts
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

0 comments on commit 508796f

Please sign in to comment.