Skip to content

core.setFailed fails if pass in an error straight from catch block #390

@fishcharlie

Description

@fishcharlie

Describe the bug

Passing an error directly into core.setFailed fails with random error ((s || "").replace is not a function).

To Reproduce
Steps to reproduce the behavior:

  1. Create failing action (example below)
  2. Ensure core.setFailed(e); instead of core.setFailed(`${e}`);
  3. Run GitHub Action

Expected behavior

It to fail with an error message of ERROR as opposed to a type error. Both core.setFailed(e); and core.setFailed(`${e}`); should produce the same result, they aren't currently.

Example Code

const core = require("@actions/core");

(async function (){
	try {
		throw new Error("ERROR");
	} catch (e) {
		core.setFailed(e);
	}
})();

Current behavior

(node:2682) UnhandledPromiseRejectionWarning: TypeError: (s || "").replace is not a function
10
    at escapeData (/.github/actions/installnpm/node_modules/@actions/core/lib/command.js:66:10)
11
    at Command.toString (/.github/actions/installnpm/node_modules/@actions/core/lib/command.js:60:35)
12
    at issueCommand (/.github/actions/installnpm/node_modules/@actions/core/lib/command.js:23:30)
13
    at Object.issue (/.github/actions/installnpm/node_modules/@actions/core/lib/command.js:27:5)
14
    at error (/.github/actions/installnpm/node_modules/@actions/core/lib/core.js:127:15)
15
    at Object.setFailed (/.github/actions/installnpm/node_modules/@actions/core/lib/core.js:101:5)
16
    at /.github/actions/installnpm/main.js:13:8
17
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
18
(node:2682) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
19

Other Notes

  • The bug was originally found in a failing await exec.exec command. I'm pretty confident that the code above will reproduce the issue, but if not, try doing it with a failing await exec.exec command.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions