mirror of https://github.com/actions/toolkit
core: Update parameter defaulting behavior for error/warning/notice to honor an empty object passed in
parent
dfc588096e
commit
bd74802644
|
@ -421,6 +421,12 @@ describe('@actions/core', () => {
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('error handles an error object and an empty properties', () => {
|
||||||
|
const message = 'this is my error message'
|
||||||
|
core.error(new Error(message), {})
|
||||||
|
assertWriteCalls([`::error::Error: ${message}${os.EOL}`])
|
||||||
|
})
|
||||||
|
|
||||||
it('error handles custom properties correctly', () => {
|
it('error handles custom properties correctly', () => {
|
||||||
const message = 'this is my error message'
|
const message = 'this is my error message'
|
||||||
core.error(new Error(message), {
|
core.error(new Error(message), {
|
||||||
|
@ -456,6 +462,12 @@ describe('@actions/core', () => {
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('warning handles an error object and an empty properties', () => {
|
||||||
|
const message = 'this is my error message'
|
||||||
|
core.warning(new Error(message), {})
|
||||||
|
assertWriteCalls([`::warning::Error: ${message}${os.EOL}`])
|
||||||
|
})
|
||||||
|
|
||||||
it('warning handles custom properties correctly', () => {
|
it('warning handles custom properties correctly', () => {
|
||||||
const message = 'this is my error message'
|
const message = 'this is my error message'
|
||||||
core.warning(new Error(message), {
|
core.warning(new Error(message), {
|
||||||
|
@ -491,6 +503,12 @@ describe('@actions/core', () => {
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('notice handles an error object and an empty properties', () => {
|
||||||
|
const message = 'this is my error message'
|
||||||
|
core.notice(new Error(message), {})
|
||||||
|
assertWriteCalls([`::notice::Error: ${message}${os.EOL}`])
|
||||||
|
})
|
||||||
|
|
||||||
it('notice handles custom properties correctly', () => {
|
it('notice handles custom properties correctly', () => {
|
||||||
const message = 'this is my error message'
|
const message = 'this is my error message'
|
||||||
core.notice(new Error(message), {
|
core.notice(new Error(message), {
|
||||||
|
|
|
@ -245,6 +245,21 @@ export function debug(message: string): void {
|
||||||
issueCommand('debug', {}, message)
|
issueCommand('debug', {}, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function defaultAnnotationPropertes(
|
||||||
|
message: string | Error,
|
||||||
|
properties: AnnotationProperties | undefined = undefined
|
||||||
|
): AnnotationProperties {
|
||||||
|
// If no properties are provided, try to extract them from the Error instance
|
||||||
|
if (properties === undefined) {
|
||||||
|
if (message instanceof Error) {
|
||||||
|
properties = toAnnotationProperties(message)
|
||||||
|
} else {
|
||||||
|
properties = {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return properties
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an error issue
|
* Adds an error issue
|
||||||
* @param message error issue message. Errors will be converted to string via toString()
|
* @param message error issue message. Errors will be converted to string via toString()
|
||||||
|
@ -252,13 +267,9 @@ export function debug(message: string): void {
|
||||||
*/
|
*/
|
||||||
export function error(
|
export function error(
|
||||||
message: string | Error,
|
message: string | Error,
|
||||||
properties: AnnotationProperties = {}
|
properties: AnnotationProperties | undefined = undefined
|
||||||
): void {
|
): void {
|
||||||
// If no properties are provided, try to extract them from the Error instance
|
properties = defaultAnnotationPropertes(message, properties)
|
||||||
properties =
|
|
||||||
Object.keys(properties).length === 0 && message instanceof Error
|
|
||||||
? toAnnotationProperties(message)
|
|
||||||
: properties
|
|
||||||
|
|
||||||
issueCommand(
|
issueCommand(
|
||||||
'error',
|
'error',
|
||||||
|
@ -274,13 +285,9 @@ export function error(
|
||||||
*/
|
*/
|
||||||
export function warning(
|
export function warning(
|
||||||
message: string | Error,
|
message: string | Error,
|
||||||
properties: AnnotationProperties = {}
|
properties: AnnotationProperties | undefined = undefined
|
||||||
): void {
|
): void {
|
||||||
// If no properties are provided, try to extract them from the Error instance
|
properties = defaultAnnotationPropertes(message, properties)
|
||||||
properties =
|
|
||||||
Object.keys(properties).length === 0 && message instanceof Error
|
|
||||||
? toAnnotationProperties(message)
|
|
||||||
: properties
|
|
||||||
|
|
||||||
issueCommand(
|
issueCommand(
|
||||||
'warning',
|
'warning',
|
||||||
|
@ -296,13 +303,9 @@ export function warning(
|
||||||
*/
|
*/
|
||||||
export function notice(
|
export function notice(
|
||||||
message: string | Error,
|
message: string | Error,
|
||||||
properties: AnnotationProperties = {}
|
properties: AnnotationProperties | undefined = undefined
|
||||||
): void {
|
): void {
|
||||||
// If no properties are provided, try to extract them from the Error instance
|
properties = defaultAnnotationPropertes(message, properties)
|
||||||
properties =
|
|
||||||
Object.keys(properties).length === 0 && message instanceof Error
|
|
||||||
? toAnnotationProperties(message)
|
|
||||||
: properties
|
|
||||||
|
|
||||||
issueCommand(
|
issueCommand(
|
||||||
'notice',
|
'notice',
|
||||||
|
|
Loading…
Reference in New Issue